Posted on 17/09/2025 23:07:25
Yes, of course. This is the code that is working local, but not in the cloud:
public class CustomFacetCacheService : ICacheStorage<string, object>
{
private static readonly Lazy<CustomFacetCacheService> _instance = new(() => new CustomFacetCacheService());
public static CustomFacetCacheService Instance => _instance.Value;
private static ServiceCache<string, object> ServiceCacheStorage { get; set; }
CacheInformation ICacheStorage.Info => ServiceCacheStorage.Info;
static CustomFacetCacheService()
{
ServiceCacheStorage = new DictionaryCache<string, object>(typeof(CustomFacetCacheService))
{
InitializeCache = InitializeCache,
FetchOnNotFound = UpdateCache,
RefreshOnClear = UpdateCache
};
}
private static Dictionary<string, object> InitializeCache()
{
return [];
}
private static Dictionary<string, object> UpdateCache(IEnumerable<string>? ids)
{
ids = ids?.Where(key => key is not null).Distinct(StringComparer.OrdinalIgnoreCase);
if ((ids?.Any()) != true == true)
{
return [];
}
return [];
}
public object? Get(string key)
{
var value = ServiceCacheStorage.GetCache(key);
return ServiceCacheStorage.GetCache(key);
}
public void SetCache(string key, object value)
{
ServiceCacheStorage.SetCache(key, value);
}
public void ClearCache()
{
ServiceCacheStorage.ClearCache();
}
public void SetCacheType<TObjectCache>() where TObjectCache : ServiceCache<string, object>
{
}
public void ClearCache(IEnumerable<string> keys)
{
ServiceCacheStorage.ClearCache(keys);
}
public void ClearCache(string key)
{
ServiceCacheStorage.ClearCache(key);
}
}