Clear cache with partial match of key

663 Views Asked by At

So I am using a C# ObjectCache instance. I have several objects stored in cache which refer to the same type of entity, but which may differ from user to user. So, for the sake of saving this item in the cache I have made a composite key which is in the following form

keyIdentifier_typeDescriptor_username 

which may have the values:

"dogKey_black_johndoe", "dogKey_white_johndoe", "dogKey_black_marydoe"

What I want to do at some point in my application is to delete all of the dog entities stored in the cache for an specific user. Something like

public void DeleteObjectFor(string objectKey, string user)

which will receive as the objectKeythe "dogKey" string, and as user "johndoe". What I want is to delete both "dogKey_black_johndoe" and "dogKey_white_johndoe" by calling the cache.Remove() method of the ObjectCache. How can I do this? Can I iterate over all of the cache elements or is there a way that I can partially match the keys? (Maybe a regex?) Greetings Luis.

0

There are 0 best solutions below