asp.net - How to set different Cache expire times for Client and Server caches -
asp.net - How to set different Cache expire times for Client and Server caches -
i have pages have 10 min cache clients , 24 hours server. reason if page changes, client fetch updated version within 10 minutes, if nil changes server have rebuild page 1 time day.
the problem output cache settings seem override client settings. here have setup:
custom actionfilterattribute class
public class clientcacheattribute : actionfilterattribute { private bool _noclientcache; public int expireminutes { get; set; } public clientcacheattribute(bool noclientcache) { _noclientcache = noclientcache; } public override void onresultexecuting(resultexecutingcontext filtercontext) { if (_noclientcache || expireminutes <= 0) { filtercontext.httpcontext.response.cache.setexpires(datetime.utcnow.adddays(-1)); filtercontext.httpcontext.response.cache.setvaliduntilexpires(false); filtercontext.httpcontext.response.cache.setrevalidation(httpcacherevalidation.allcaches); filtercontext.httpcontext.response.cache.setcacheability(httpcacheability.nocache); filtercontext.httpcontext.response.cache.setnostore(); } else { filtercontext.httpcontext.response.cache.setexpires(datetime.utcnow.addminutes(expireminutes)); } base.onresultexecuting(filtercontext); } }
web config settings
<outputcachesettings> <outputcacheprofiles> <add name="cache24hours" location="server" duration="86400" varybyparam="none" /> </outputcacheprofiles> </outputcachesettings>
how i'm calling it:
[outputcache(cacheprofile = "cache24hours")] [clientcacheattribute(false, expireminutes = 10)] public class homecontroller : controller { [...] }
but looking @ http header shows:
http/1.1 200 ok cache-control: no-cache pragma: no-cache content-type: text/html; charset=utf-8 expires: -1
how can implement properly? asp.net mvc 4 application.
you need implement own solution server side caching , client side caching either utilize clientcacheattribute or outputcache. here reason why require custom solution server side cache.
clientcacheattribute sets cache policy response.cache type of httpcachepolicybase and built-in outputcache sets cache policy response.cachehere i'm trying highlight we don't have collection of httpcachepolicybase have 1 object of httpcachepolicybase can't set multiple cache policy given response.
even if can set http cacheability httpcacheability.serverandprivate 1 time again run in other issue cache duration (i.e. client 10 min & server 24 hours)
what suggest utilize outputcache client side caching , implement own caching mechanism server side caching.
asp.net asp.net-mvc caching outputcache
Comments
Post a Comment