alastairtree / LazyCache

An easy to use thread safe in-memory caching service with a simple developer friendly API for c#
https://nuget.org/packages/LazyCache
MIT License
1.72k stars 159 forks source link

Please add a Clear() method #195

Open DavidThielen opened 7 months ago

DavidThielen commented 7 months ago

Disposing and then creating a new cache is problematic at times. Having a Clear() method resolves that.

I think adding ICacheProvider.Clear() is the best way to do this. But here is code that works:

       public static void ExClear(this IAppCache service)
       {
        IMemoryCache? provider = service.CacheProvider.GetPrivateFieldValue<IMemoryCache>("cache");
        if (provider is MemoryCache memoryCache)
            memoryCache.Clear();
           else Trap.Break(); // need to find a solution for this!!!
       }
yaugkeer commented 3 months ago

sure