I am using python 2.7.3 with varnish-3.0.2.
I am using python urllib2 library.
I wish to force the server to bring back the latest data from the DB and not to use the varnish cache so I added the following to my request
req.add_header('Pragma', 'no-cache');
req.add_header('Cache-Control', 'no-cache');
But this does not work - it has no effect.
Here is a code snippet:
req = urllib2.Request(url='http://%s:%d/api/myquery/myrequest' % (self.host, self.port))
return self.httpreq(req)
.
.
def httpreq(self, req, data=None):
req.add_header('Pragma', 'no-cache');
req.add_header('Cache-Control', 'no-cache');
try:
http_handler = urllib2.HTTPHandler(debuglevel=1)
opener = urllib2.build_opener(http_handler, urllib2.HTTPCookieProcessor(self.cj))
if data:
req = opener.open(req, data, timeout=wwbsettings.HTTP_TIMEOUT)
else:
req = opener.open(req, timeout=wwbsettings.HTTP_TIMEOUT)
resp = req.read()
log('data=%s' % resp)
content = json.loads(resp)
return content
except urllib2.HTTPError as e:
resp = e.read()
log('HTTPError: %s - %s' % (e, resp))
content = json.loads(resp)
return content
except urllib2.URLError as e:
log('URLError: %s' % e)
return None
except Exception as e:
log('Exceptions: %s' % e)
return None
And here is the request header:
header: Server: nginx/1.1.19
header: Date: Mon, 12 Jan 2015 17:51:22 GMT
header: Content-Type: application/json
header: Content-Length: 636
header: Connection: close
header: Vary: Accept
header: ETag: "acfa981667dfb6de47881623ad092672"
header: Allow: HEAD, GET, OPTIONS
header: Cache-Control: s-maxage=604800, public, max-age=300
header: Accept-Ranges: bytes
header: X-Varnish: 1115442413
header: Age: 0
header: Via: 1.1 varnish
header: X-Varnish-Cache: MISS
I do not receive the latest data in my response - can anyone help here? Much appreciated.