Is there a way to get all the keys from an ISynchronizedObjectInstanceCache instance?
I don't think we do have any method to get all at once.
What action you want to perform by retrieving all keys?
I want to invalidate all items where the key starts with a given string
If you have a fixed set of possible keys, iterate over those and call cache.Remove(key) for each...
It is not a fixed set
ISynchronizedObjectInstanceCache may be using EPiServer.Framework.Cache.HttpRuntimeCache which, in turn, uses System.Web.HttpRuntime.Cache.
If that is the case, you could simply call:
Feels like kinda long shot, but worth trying...?
By default ISynchronizedObjectInstanceCache uses HttpRuntimeCache which uses HttpRuntime.Cache internally, so you can use Tomas approach. But you can have a custom implementation and that will break.
Iterate over cache keys is NOT a good idea. A better solution is to use master key. If you have key with same prefixes, then better add that prefix as the master key. Once you want to invalidate the cache entries you can just remove that master key and everything will be taken care for you.
I took custom implementation approach. Defined my own cache manager interface and all required methods. Why you might ask? Well.. under the same abstractions I need to support multiple implementations - episerver, aspnet default, netcore implementation and who knows - maybe some day custom consuming project defined implementation. This is approach taken in my localization provider..
also, as Quan mentioned - iteration over all keys is not recommended. Having my own implementation - I can cluster keys and iterate over just my own stuff if needed.