Tutorial :Does the Python library httplib2 cache URIs with GET strings?


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")  


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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »