c# - System.Net.Http.HttpClient caching behavior -


i'm using httpclient 0.6.0 nuget.

i have following c# code:

var client = new httpclient(new webrequesthandler() {     cachepolicy =         new httprequestcachepolicy(httprequestcachelevel.cacheifavailable) }); client.getasync("http://myservice/asdf"); 

the service (this time couchdb) returns etag value , status code 200 ok. there returned cache-control header value must-revalidate

update, here response headers couchdb (taken visual studio debugger):

server: couchdb/1.1.1 (erlang otp/r14b04) etag: "1-27964df653cea4316d0acbab10fd9c04" date: fri, 09 dec 2011 11:56:07 gmt cache-control: must-revalidate 

next time exact same request, httpclient conditional request , gets 304 not modified. right.

however, if using low-level httpwebrequest class same cachepolicy, request isn't made second time. way want httpclient behave.

is must-revalidate header value or why httpclient behaving differently? 1 request , have rest cache without conditional request..

(also, side-note, when debugging, response status code shown 200 ok, though service returns 304 not modified)

both clients behave correctly.

must-revalidate applies stale responses.

when must-revalidate directive present in response received cache, cache must not use entry after becomes stale respond subsequent request without first revalidating origin server. (i.e., cache must end-to-end revalidation every time, if, based solely on origin server's expires or max-age value, the cached response stale.)

since not provide explicit expiration, caches allowed use heuristics determine freshness.

since not provide last-modified caches do not need warn client heuristics used.

if none of expires, cache-control: max-age, or cache-control: s- maxage (see section 14.9.3) appears in response, , response not include other restrictions on caching, the cache may compute freshness lifetime using heuristic. cache must attach warning 113 response whose age more 24 hours if such warning has not been added.

the response age calculated based on date header since age not present.

if response still fresh according heuristic expiration, caches may use stored response.

one explanation httpwebrequest uses heuristics , there stored response status code 200 still fresh.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -