ISynchronizedObjectInstanceCache - how do I get all the keys in the cache?


Is there a way to get all the keys from an ISynchronizedObjectInstanceCache instance?

Oct 01, 2019 9:56

I don't think we do have any method to get all at once.

What action you want to perform by retrieving all keys?

Oct 01, 2019 10:18

I want to invalidate all items where the key starts with a given string

Oct 01, 2019 10:22
Praful Jangid - Oct 01, 2019 10:49
In that case looping is the only solution by passing actual key value.

If you have a fixed set of possible keys, iterate over those and call cache.Remove(key) for each...

Edited, Oct 01, 2019 10:23

It is not a fixed set

Oct 01, 2019 10:25

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...?

Edited, Oct 01, 2019 14:13

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.

Oct 01, 2019 14:20


Oct 01, 2019 14:22

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..

Oct 01, 2019 18:20

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.

Oct 01, 2019 18:21
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.