Skip to content

Documentation

Jean-Michel Julien edited this page Jul 5, 2017 · 1 revision

The TinyThreadSafeCache Class

ClassDiagram.png

Methods

Add : This method will replace existing item or add if it does not already exist.
Get : This is to get an item from the cache by its key, it will return null if not found.
Delete : This method is to remove an item from the cache by its key.
Purge : This method empty the whole cache.
Exist : This method validates that a key exists in the cache.
Size : This methods gets the number of items saved in the cache.

Usage

You can instanciate the class normally :

TinyThreadSafeCache<MyTypeToCache> MyCache = new TinyThreadSafeCache<MyTypeToCache>();

Or if like me you prefer the accessibility of a singleton, you can derive it :

sealed class MySingletonCache
{
  //singleton private instance
  private static readonly TinyThreadSafeCache<MyTypeToCache> _instance = 
    new TinyThreadSafeCache<MyTypeToCache>(); 
  
  private MySingletonCache() { } // Make sure nobody can call constructor

  public static TinyThreadSafeCache<MyTypeToCache> Instance
  {
    get
    {
      return _instance;
    }
  }
}

And use it anywhere :

MySingletonCache.Instance.Purge();
Clone this wiki locally