removing items form cache where Cache key starts with

Topics: Caching Application Block
Dec 19, 2008 at 1:37 AM

We are using Ent Lib 4.1 and need to find a way to remove items from the cache where the cache key starts with, something like this. We are caching subsets of our data and it makes it hard to know the exact cache key so the easiest for us would be to delete the items as show below. I added this piece of code to the Ent Lib 3.1 caching block and it worked but in 4.1 this is no longer possible.








/// Removes items from the cache whose key starts with the input prefix.




/// </summary>
// <param name="prefix">Prefix for the cache items to be removed.</param>




public void RemoveItemsFromCache(string prefix){



IList<string> itemsToRemove = new List<string>();



foreach (string key in inMemoryCache.Keys){



if (key.StartsWith(prefix))




//Add item to remove to ArrayList().








foreach (string key in itemsToRemove)




//Remove item from cache.




Dec 19, 2008 at 3:18 AM
What type of object is the inMemoryCache?  And what do you mean it's no longer possible? Are you getting a compile error or runtime error?

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.