Remove cache keys with key pattern
Description
I have hybrid caching implemented on my system by using in-memory and redis provider, I want to be able to remove cache keys by a key pattern, for example, I have the following keys:
- configurations:games:ranks
- configurations:games:players
What I want to remove here is any key that includes games, so, I'd have a key pattern that looks like *games*
I tried to use IHybridCachingProvider.RemoveAsync which uses unlink command in redis, by using *games* as the key it would run the following command in redis that does not remove any keys:
unlink *games*
Then I wanted to try with IHybridCachingProvider.RemoveByPrefixAsync which uses scan to find the keys with the pattern that only ends with *, because it replaces the * in the pattern that I'm passing so *games* becomes games* that does not find the keys that I'm targetting.
scan 0 match games* count 200
https://github.com/dotnetcore/EasyCaching/blob/bac207ba604c75f5a9f9e687d07be2453cbf9ee7/src/EasyCaching.Redis/DefaultRedisCachingProvider.cs#L279
https://github.com/dotnetcore/EasyCaching/blob/bac207ba604c75f5a9f9e687d07be2453cbf9ee7/src/EasyCaching.Redis/DefaultRedisCachingProvider.cs#L341-L358
Expected
The expected redis command that works for this issue is as following,
scan 0 match *games* count 200
The requirement here is to have a new method or any other solution to be able to remove keys by a pattern that is not limited by only a prefix. I'd be glad to contribute to this because it's a necessary feature for our project.
Specifications
- Provider : EasyCaching.HybridCache (1.6.1)
- Interceptor : AspectCore (6.0.0)
@xsoheilalizadeh Thanks for your interest in this project.
This will be a great feature!!! Contributions are welcome. 😄
Thanks, I'll look into it.