CachingCallHandler - How to clear cache?

Topics: Policy Injection Application Block
Nov 7, 2008 at 7:34 AM
I neet to clear cache for concrete policy or handler. Is it possible?
Nov 7, 2008 at 8:14 AM
Using the Flush method of the CacheManager will remove all items in it, but what do you mean by "for concrete policy or handler"?

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
Nov 7, 2008 at 10:08 AM
AFAIK, CachingCallHandler don't use CacheManager
Nov 7, 2008 at 12:46 PM
Sorry, got confused.  I don't see any way to do this since the CachingCallHandler class doesn't expose any of its properties and in addition, there's no method for removing or clearing the items. 
Feb 12, 2009 at 1:59 AM
I would like to solve this issue as well but the only way i can really think of doing this is by finding the cached item in the cache list by searching for the key with the method name in it and removing it manually. Not very elegant. The cachecallhandler creates cached keys based on some hash of the method being invoked and because it creates different cached entries for each parameter combination, it would be quite hard to figure out exactly which cache item to remove. If you don't care about which entry is removed and want to remove all entries based on a particular method, you can search the cached keys that end in your method name. For example an entry in the cache created by the cachecallhander would be:


but based on the parameters of GetStuff, you might have a whole bunch of entries similar to the above.
Apr 16, 2009 at 10:40 AM
Seriously, this is a huge show stopper for using the policy injection caching in my enterprise application.  I cannot be putting things into the cache without a clear and reliable method to remove them. As it's possible sometimes that cached items have changed prior to expiration, and will need manual intervention
Apr 16, 2009 at 11:00 AM
There's no direct support for removing the entry from the cache.  What Shandem suggested kind of gives you an idea.  You could create your own cachingcallhandler probably leveraging the caching feature built in entlib and would make it easier for you to determine the key you need to remove the item from the cache.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
Apr 16, 2009 at 11:40 PM
The caching call handler is really more of a proof of concept than a full-featured caching system. In fact, I should have named it "MemoizationCallHandler", as that's what it really does.

If you need more control your best bet is to write your own call handler that matches your specific requirements.
Apr 17, 2009 at 11:51 AM
Ok, thanks for the quick replies.

FYI. This is the last shred of evidence i need to ban EL from our development for ever now. it's all a great idea, but so heavy for a half implemented factory. i'll stick with java ports and other open source i think from now on
Jun 2, 2009 at 8:22 PM
Edited Jun 5, 2009 at 12:55 PM

// get the key generated by the CachingCallHandler

System.Reflection.MethodInfo cachedMethod = this.GetType().GetMethod("cachedMethodName");
object[] args = new object[]{ /*method call args values*/ };

string key = new DefaultCacheKeyGenerator().CreateCacheKey(cachedMethod, args);


// remove from the cache