using Microsoft.Extensions.Caching.Memory;
public static void Main()
IMemoryCache cache = new MemoryCache(new MemoryCacheOptions());
object key = new object();
Console.WriteLine("{0}", cache.TryGetValue(key, out int val)?val:"key not found");
Console.WriteLine(cache.Get(key));
Console.WriteLine(cache.Get(key));
public static void Incr(object key, IMemoryCache cache)
int currentValue = cache.GetOrCreate(key, _ => 0);
cache.Set(key, currentValue+1);