Skip to content

Instantly share code, notes, and snippets.

@GiuseppeMP
Forked from srkirkland/cachesingeton.cs
Created October 6, 2020 01:08
Show Gist options
  • Save GiuseppeMP/d748b846b3931d55522b4b1b2c95753b to your computer and use it in GitHub Desktop.
Save GiuseppeMP/d748b846b3931d55522b4b1b2c95753b to your computer and use it in GitHub Desktop.
Singleton for creating a cache factory for Azure Caching. Creates the DataCacheFactory only once and stores it in CacheFactory.Instance. Can then get a desired DataCache by calling CacheFactory.Instance.GetCache("CacheName");
public static class CacheFactory
{
/// <summary>
/// This is a thread-safe, lazy singleton. See http://www.yoda.arachsys.com/csharp/singleton.html
/// for more details about its implementation.
/// </summary>
public static DataCacheFactory Instance
{
get { return Nested.CacheFactory; }
}
private class Nested
{
internal static readonly DataCacheFactory CacheFactory = new DataCacheFactory();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment