This is how I am creating a cache key
string cachekey_base = "IR_";
string symbol = "AUD";
static string id = "12345";
string cacheKey_Quote = $"{cachekey_base}{symbol}{id}Quote";
The id is generated randomly so if I know the id then simply remove the cache like this
MemoryCache.Default.Remove(key);
But the problem is Id
can be any random number.
So is there e a way to remove using contains keyword.
For example in my case remove all cache if key contains `"IR_"
Any help or suggestion would be appreciated .
Thanks in advance`
you can filter keys you want to remove them then iterate over these keys and remove them as following:
var removedKeys = MemoryCache.Default.Where( x=> x.Key.Contains("IR_")).Select(x=> x.Key).ToList();
foreach(var key in removedKeys)
MemoryCache.Default.Remove(key);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With