Search code examples
cachingserenity-platform

How to get all cache keys in Serenity-Platform?


I want to develop a page where all the cache lists will show and the user can clear a cache by clicking a button.

But I am facing a problem to get all the cache keys which have been set.


Solution

  • Serenity doesn't needs cache keys as list. So there is no way to retrieve keys from serenity cache classes.

    If you need to retrieve keys, you can create new classes what implement IDistributedCache and/or ILocalCache. Then register this classes from startup.cs. Also don't forget to remove serenity code from there

    enter image description here

    And before you register your own cache implementation, don't forget to add services.AddMemoryCache(); for memory cache implementation if you use.

    enter image description here

    Then you can get your implementation everywhere like code below. StaticProvider property is resolves registered classes for you.

            (LocalCache.StaticProvider as MyCustomLocalCacheProvider).GetAllKeys();
            (DistributedCache.StaticProvider as MyCustomDistributedCacheProvider).GetAllKeys();