using KGySoft.Collections;
using KGySoft.CoreLibraries;
public static void Main()
var cacheOptions = new LockingCacheOptions
Expiration = TimeSpan.FromMilliseconds(100)
var cache = ThreadSafeCacheFactory.Create<int, string>(LoadCacheValue, cacheOptions);
Console.WriteLine(cache[42]);
Console.WriteLine(cache[42]);
System.Threading.Thread.Sleep(200);
Console.WriteLine(cache[42]);
private static string LoadCacheValue(int key)
Console.WriteLine($"Obtaining value for key {key}");
return Random.Shared.NextString();