C# | Caching
MemoryCache
Section titled “MemoryCache”//Get instance of cacheusing System.Runtime.Caching;
var cache = MemoryCache.Default;
//Check if cache contains an item withcache.Contains("CacheKey");
//get item from cachevar item = cache.Get("CacheKey");
//get item from cache or add item if not existingobject list = MemoryCache.Default.AddOrGetExisting("CacheKey", "object to be stored", DateTime.Now.AddHours(12));
//note if item not existing the item is added by this method//but the method returns null