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

Vote:
 

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

#207710
Oct 01, 2019 9:56
Vote:
 

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

What action you want to perform by retrieving all keys?

#207715
Oct 01, 2019 10:18
Vote:
 

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

#207717
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.
Vote:
 

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

#207718
Edited, Oct 01, 2019 10:22
Vote:
 

It is not a fixed set

#207719
Oct 01, 2019 10:25
Vote:
 

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:

HttpRuntime.Cache.GetEnumerator()

Feels like kinda long shot, but worth trying...?

#207728
Edited, Oct 01, 2019 13:41
Vote:
 

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.

#207729
Oct 01, 2019 14:20
Vote:
 

Thanks!

#207730
Oct 01, 2019 14:22
Vote:
 

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

#207751
Oct 01, 2019 18:20
Vote:
 

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.

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