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
Post a Comment