1

varnish-3.0.2 で python 2.7.3 を使用しています。

Python urllib2 ライブラリを使用しています。

サーバーにDBから最新のデータを強制的に戻し、ワニスキャッシュを使用しないようにしたいので、リクエストに次を追加しました

    req.add_header('Pragma', 'no-cache');
    req.add_header('Cache-Control', 'no-cache');

しかし、これは機能しません。効果はありません。

コード スニペットを次に示します。

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

そして、ここにリクエストヘッダーがあります:

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

応答で最新のデータを受け取りません。誰か助けてもらえますか? とても有難い。

4

0 に答える 0