MichaCo / CacheManager

CacheManager is an open source caching abstraction layer for .NET written in C#. It supports various cache providers and implements many advanced features.
http://cachemanager.michaco.net
Apache License 2.0
2.33k stars 457 forks source link

Not possible to flush whole cache when using in-memory and redis handles #360

Open djb-frog opened 2 years ago

djb-frog commented 2 years ago

Our caching configuration uses both in-memory cache and Redis. Additionally we rely on Redis keyspace notifications to clear keys from the in-memory caches across all our app service instances.

One problem we are having is something bad gets into the cache, we want to flush redis and also flush in-memory cache on all instances. Is this possible? Does ICacheManager.Clear propagage the cache clear to clear in-memory cache on all instances?

Assuming it doesn't, I was thinking we could use a region that contains all our cache items so we can clear the region to clear Redis and all the instance caches in one go. Is it possible to prefix all our regions with a global region name? My testing indicates that each cache item can only belong to one region and there is no concept of multiple regions or region prefixes.

If I create items in regions called "ALL:regionone", "ALL:regiontwo"

// This works as expected: _cacheManager.DeleteRegion("ALL:regionone");

// Didn't 100% expect this to work, but this does not clear any of my items: _cacheManager.DeleteRegion("ALL");

Any advice greatly appreciated!

David

djb-frog commented 2 years ago

Hi,

I just tried it out some tests again and your Clear action is being propagated with Redis between my 2 test instances - apologies for the false alarm!

So that's my main problem fixed :) I guess I'm just wondering if you can confirm is there any way to have more than 1 region or region prefix associated with a cached item?

Thanks

David

MichaCo commented 2 years ago

Yeah clear should just work.

One key can currently only be on one region, but you can ofc add the key to multiple regions, would just be Add multiple calls for example.