i using asp.net webapi , have following code stop caching in everything:
public override system.threading.tasks.task<httpresponsemessage> executeasync(system.web.http.controllers.httpcontrollercontext controllercontext, system.threading.cancellationtoken cancellationtoken) { system.threading.tasks.task<httpresponsemessage> task = base.executeasync(controllercontext, cancellationtoken); task.getawaiter().oncompleted(() => { task.result.headers.cachecontrol = new cachecontrolheadervalue() { nocache = true, nostore = true, maxage = new timespan(0), mustrevalidate = true }; task.result.headers.pragma.add(new namevalueheadervalue("no-cache")); task.result.content.headers.expires = datetimeoffset.minvalue; }); return task; } the result headers (chrome):
cache-control:no-store, must-revalidate, no-cache, max-age=0 content-length:1891 content-type:application/json; charset=utf-8 date:fri, 19 jul 2013 20:40:23 gmt expires:mon, 01 jan 0001 00:00:00 gmt pragma:no-cache server:microsoft-iis/8.0 i added "no-store" after reading bug (how stop chrome caching).
however, no matter do, when navigates me away page, , use "back" button, chrome loads cache:
request method:get status code:200 ok (from cache) does have idea why happening? have confirmed server never hit request.
the answer chrome not "expires:mon, 01 jan 0001 00:00:00 gmt" (a fake date, basically).
i changed date use in google api, , worked:
cache-control:no-store, must-revalidate, no-cache, max-age=0 content-length:1897 content-type:application/json; charset=utf-8 date:fri, 19 jul 2013 20:51:49 gmt expires:mon, 01 jan 1990 00:00:00 gmt pragma:no-cache server:microsoft-iis/8.0 so, else comes across problem, make sure set expires date arbitrary date!
Comments
Post a Comment