AutoStorage 5.0.0
dotnet add package AutoStorage --version 5.0.0
NuGet\Install-Package AutoStorage -Version 5.0.0
<PackageReference Include="AutoStorage" Version="5.0.0" />
paket add AutoStorage --version 5.0.0
#r "nuget: AutoStorage, 5.0.0"
// Install AutoStorage as a Cake Addin #addin nuget:?package=AutoStorage&version=5.0.0 // Install AutoStorage as a Cake Tool #tool nuget:?package=AutoStorage&version=5.0.0
Overview
AutoStorage is the collection that allows specifying storage time for elements stored in it. Default storage time that can be set when collection is initialized (unlimited by default) is assigned to each element unless overriden upon addition. When storage time of an element is elapsed an event with all the neccessary information about it including the element itself is raised.
StorageTime
AutoStorage<T>
uses StorageTime
struct for representing the concept of time in milliseconds. It supports implicit conversion from any numeric value, TimeSpan
and Interval
which is another struct defined in my other GTimer library.
using System.Timers;
StorageTime fromTimeSpan = TimeSpan.FromMilliseconds(100);
StorageTime fromInterval = Interval.Default;
StorageTime fromInteger = 100;
StorageTime fromLong = 100L;
StorageTime fromDouble = 100d;
StorageTime fromFloat = 100f;
StorageTime
itself defines some special values. Although they are backed by actual numeric values, they should be used only when working with AutoStorage<T>
as that's the only meaningful context for them. These are StorageTime.Unlimited
and StorageTime.Default
. Instances of StorageTime
should be checked for being equal to these values using following fields:
((StorageTime)StorageTime.Unlimited).IsUnlimited
((StorageTime)StorageTime.Default).IsDefault
AutoStorageItem<T>
AutoStorageItem<T>
is the class used for internal representation of elements inside AutoStorage<T>
with its equality contract based on the equality contract of T
. It wraps the element of type T
and StorageTimer
used for monitoring its storage time. StorageTimer
provides read-only access to some properties of GTimer
that might be of any interest to the user. Instances of AutoStorageItem
can only be obtained via ItemStorageTimeElapsed
event which is defined as EventHandler<AutoStorageItem<T>>
.
AutoStorage<T>
AutoStorage<T>
defines constructors that take the same set of parameters that most collections do with the additional optional StorageTime defaultStorageTime
parameter. Initializing AutoStorage<T>
without explicitly providing StorageTime
as the constructor argument sets its DefaultStorageTime
to StorageTime.Unlimited
which is assigned to any element that is added without specifying different one instead. Passing StorageTime.Default
as the constructor argument is functionally equivalent to passing StorageTime.Unlimited
or calling default constructor.
new AutoStorage<T>().DefaultStorageTime == new AutoStorage<T>(StorageTime.Default).DefaultStorageTime == new AutoStorage<T>(StorageTime.Unlimited).DefaultStorageTime;
But passing StorageTime.Default
as one of the arguments to methods that populate AutoStorage<T>
sets the storage time of the element being added to DefaultStorageTime
of that AutoStorage<T>
instance. Overloads that don't accept StorageTime storageTime
as one of the arguments have the same behavior.
// Functionally the same.
autoStorage.Add(a);
autoStorage.Add(b, StorageTime.Default);
Methods
public T AddOrUpdateValue(T value, T updatedValue, bool resetStorageTime = true)
public void AddOrUpdateStorageTime(T value, StorageTime storageTime)
public void AddOrResetStorageTime(T value)
public void AddOrResetStorageTime(T value, StorageTime storageTime)
public bool TryResetStorageTime(T value)
public bool TryUpdateValue(T value, T updatedValue, bool resetStorageTime = true)
public bool TryUpdateStorageTime(T value, StorageTime storageTime)
public T GetOrAddValue(T value)
public T GetOrAddValue(T value, StorageTime storageTime)
public StorageTimer GetSorageTimerOrAdd(T value)
public StorageTimer GetSorageTimerOrAdd(T value, StorageTime storageTime)
public bool TryGetValue(T value, [MaybeNullWhen(false)] out T storedValue)
public bool TryGetStorageTimer(T value, [MaybeNullWhen(false)] out StorageTimer storageTimer)
Installation
For guidance on how to install NuGet packages refer here and here.
Suggestions
If you would like to see some additional functionality that isn't provided by this library yet, feel free to leave your proposals in Issues section. Any feedback is highly appreciated.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- GTimer (>= 1.5.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AutoStorage:
Package | Downloads |
---|---|
GIBS
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
5.0.0 | 824 | 12/24/2022 |
4.1.0 | 401 | 9/2/2022 |
4.0.2 | 392 | 9/2/2022 |
4.0.0 | 390 | 9/1/2022 |
3.0.1 | 407 | 8/31/2022 |
3.0.0 | 391 | 8/31/2022 |
2.6.0 | 402 | 8/30/2022 |
2.5.0 | 393 | 8/29/2022 |
2.4.0 | 382 | 8/29/2022 |
2.3.0 | 379 | 8/29/2022 |
2.2.0 | 378 | 8/29/2022 |
2.1.0 | 374 | 8/29/2022 |
2.0.0 | 385 | 8/29/2022 |
1.0.0 | 382 | 8/28/2022 |