I have some inherited code still running on .net framework 4.7.2 its a webapi. This runs in aws in windows containers. The calls to it are resource intensive and thus there is quite a bit of caching the caching its using HttpRuntime.Cache.
Issue we have at the moment is that the caching is per instance ideally it should be using a distributed cache like redis. In the calls to HttpRuntime.Cache.Insert we have:
public async Task<T> CacheAndGet<T>(string key, Func<Task<T>> cacheFunction, Func<CacheDependency> cacheDependency) where T : class
{
var result = Get<T>(key);
if (result == null)
{
Log.Warning("cache is empty for for {cacheKey}", key);
result = await cacheFunction();
Put(key, result, cacheDependency());
}
return result;
}
private static void Put<T>(string key, T value, CacheDependency cacheDependency)
{
if (EqualityComparer<T>.Default.Equals(value, default(T))) return;
HttpRuntime.Cache.Insert(key, value, cacheDependency);
}
The thing I am struggling with is how to replicate the cacheDependancy part with redis. Is it possible to replicate dependancy based caching with redis? I did read something about tagging with redis sets? Is this the way to go? Anyone done anything like this before?