views:

226

answers:

2

In the following example what is cached correctly? Is there a Vary-Header I have to set server-side for the GET string?

import httplib2
h = httplib2.Http(".cache")
resp, content = h.request("http://test.com/list/")
resp, content = h.request("http://test.com/list?limit=10")
resp, content = h.request("http://test.com/list?limit=50")
A: 

http://www.xml.com/pub/a/2006/02/01/doing-http-caching-right-introducing-httplib2.html

vartec
I have read that before but it doesn't answer my question.
Jason Christa
Actually it does, states clearly, that httplib2 uses ETag and Last-Modified to determine if the content has changed.
vartec
+2  A: 

httplib2 uses the full URI for the cache key, so in this case each of the URLs you have in your example will be cached separately by the client.

For the chapter and verse from the __init__.py file for httplib2, if you would like proof, have a look at call to the cache on around line 1000:

cachekey = defrag_uri
cached_value = self.cache.get(cachekey)

The defrag_uri is defined by the function urlnorm (line 170ish) and includes the scheme, authority, path, and query.

Of course, as you know, the server may interpret the definition of "resource" quite differently and, so, may still return cached content. Since it sounds like you're controlling the server in this case, you have full control there, so no issues. Either way, on the client side, there would be no client-cached values used for the first call to each of the 3 URLs in your examples.

Jarret Hardie