c# - How do I figure out the names of OutputCache items? -


i have situation in across our app, there lot of content can put in outputcache, content can refreshed user @ point. need clear cache when user instigates refresh action.

i assumed simple enough, httpresponse has method removefromoutputcache. method takes string name of item has been cached. not there easy way list of item names have been cached.

as result have overriden outputcacheattribute following class:

public class hierarchyoutputcache : outputcacheattribute {     public static readonly concurrentbag<string> cachedpages = new concurrentbag<string>();      public hierarchyoutputcache(params string[] varyparameters)     {         location = outputcachelocation.server;         duration = int.maxvalue;         varybyparam = string.join(";", varyparameters);     }      public override void onactionexecuted(actionexecutedcontext filtercontext)     {         base.onactionexecuted(filtercontext);         cachedpages.add(filtercontext.httpcontext.request.rawurl);     } } 

then when action hit in application can following:

hierarchyoutputcache.cachedpages.foreach(response.removeoutputcacheitem);

however, response.removeoutputcacheitem isn't working, assume because passing incorrect string rawurl storing in attribute.

i cannot find information anywhere name should be, can help?

i solved using following item name in hierarchyoutputcache class:

public override void onactionexecuted(actionexecutedcontext filtercontext) {     base.onactionexecuted(filtercontext);     cachedpages.add(filtercontext.httpcontext.request.currentexecutionfilepath); } 

this meant call hierarchyoutputcache.cachedpages.foreach(response.removeoutputcacheitem) worked expected!


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -