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.34k stars 457 forks source link

CacheManager global key or region prefix #232

Closed LRFalk01 closed 6 years ago

LRFalk01 commented 6 years ago

I'm looking for a way to automatically prefix all cached items. I'm in a situation where an application runs an instance per customer, but the redis cache would be a single server. It's a fairly clear use case for regions I think, however it would really be nice if we could somehow define a global region that is automatically applied to an app domain. Is this possible?

MichaCo commented 6 years ago

Region in Redis has some overhead as CM has to keep a lookup with all keys in the region. It will also have some limitations over time.

To just have a prefix on your keys, the easiest way is to do that on your side and just add a customer or "tenant" identifier on each key you store in the cache. String concatenation, that's the easiest thing ;)

If you can afford a Redis connection per customer, you can also use different Redis databases

LRFalk01 commented 6 years ago

Thanks for the response. What I have setup now is a wrapper around BaseCacheManager where when you set/get cache the key is prefixed with an instance specific key. Our internal CacheManagerFactory returns this instead of BaseCacheManager. I'm going to test this tomorrow to make sure it works the way I think it should ;)

LRFalk01 commented 6 years ago

My abstraction is working like a champ. Thanks for your help.