AutoStorage 5.0.0

dotnet add package AutoStorage --version 5.0.0                
NuGet\Install-Package AutoStorage -Version 5.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AutoStorage" Version="5.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AutoStorage --version 5.0.0                
#r "nuget: AutoStorage, 5.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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                


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.


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:



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> 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(b, StorageTime.Default);
    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)


NuGet Download page

For guidance on how to install NuGet packages refer here and here.


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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on AutoStorage:

Package Downloads

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.0.0 788 12/24/2022
4.1.0 394 9/2/2022
4.0.2 384 9/2/2022
4.0.0 383 9/1/2022
3.0.1 398 8/31/2022
3.0.0 384 8/31/2022
2.6.0 395 8/30/2022
2.5.0 384 8/29/2022
2.4.0 375 8/29/2022
2.3.0 370 8/29/2022
2.2.0 369 8/29/2022
2.1.0 365 8/29/2022
2.0.0 376 8/29/2022
1.0.0 372 8/28/2022