Open ebortolini opened 6 years ago
Simple answer is, there is currently no supported way to do this.
Long answer for filtering and searching keys in Cache: Caching with multiple layers and especially distributed caches can become pretty complex. That's why most caches don't provide any ways to find keys.
Have a look at System.Runtime.Caching or MS.Extensions.Caching.Memory. There is no way to retrieve all keys or search for keys with prefix or anything. For example, the implementation of Regions in CacheManager for those two caches uses dependencies to delete all keys in a Region. But there is no way to find all keys of a region.
The Redis implementation uses a lookup key to store a link to all keys stored in a region. Yes, this could be used and returned to the user of CacheManager. The problem here is, I cannot ensure that list is consistent at all. Keys in that list might already be expired or just other things happend. In short, there is no way to provide a good consistency in this imlpementation (although CacheManager tries really hard to keep that consistent)
Then, if you use CacheManager for 2 layers of cache, e.g. in-memory+redis, finding everything in a Region would have to retrieve the list from Redis, as the in-memory layer might not even have all keys.
We already tried a few things, like searching for keys (see #161 for example).
So far, I don't have a really good and efficient API concept for this, otherwise I'd have implemented it already ;)
That being said, it is and always was on my list of things I'd like to have, too
I am using the regions in cache. I could verify that is possible to remove all items from a specific region. But looking in documentation I couldn't find a way to filter by region. By example: If a have a set of items, and some itens are in region A, some other in region B, and so on ... I didn't find an efficient way to filter only items from region A.
Are you planning to have someting like this?