asp.net web api - Sitecore and caching control -
i working on sitecore project , using webapi perform service calls. methods decorated cacheoutput information this:
[httpget] [cacheoutput(clienttimespan = 3600, servertimespan = 3600)]
i testing these calls using dhc app on google chrome. sure clienttimespan set correctly response headers getting not expecting. expect cache-control have max-age of 1hour set clienttimespan attribute instead set private. have been debugging possible , t turns out sitecore may intercepting response , setting header value private. have added service url sitecore ignored url preffixes configuration no .
anyone has idea how can make sitecore not change cache-control headers?
this default mvc behaviour , not directly related sitecore / web api.
can create custom attribute sets cache-control
header:
public class cachecontrol : system.web.http.filters.actionfilterattribute { public int maxage { get; set; } public cachecontrol() { maxage = 3600; } public override void onactionexecuted(httpactionexecutedcontext context) { context.response.headers.cachecontrol = new cachecontrolheadervalue() { public = true, maxage = timespan.fromseconds(maxage) }; base.onactionexecuted(context); } }
which enables add [cachecontrol(maxage = n)]
attribute methods.
code taken from: setting http cache control headers in webapi (answer #2)
or can apply globally throughout application, explained here: http://juristr.com/blog/2012/10/output-caching-in-aspnet-mvc/
Comments
Post a Comment