add header showing brotli cache status

This commit is contained in:
codl 2017-08-12 22:01:42 +02:00
parent cdff524e3d
commit 639d209a95
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
1 changed files with 2 additions and 0 deletions

View File

@ -26,7 +26,9 @@ class BrotliCache(object):
cache_key = 'brotlicache:{}'.format(digest)
encbody = self.redis.get(cache_key)
response.headers.set('x-brotli-cache', 'HIT')
if not encbody:
response.headers.set('x-brotli-cache', 'MISS')
lock_key = 'brotlicache:lock:{}'.format(digest)
if self.redis.set(lock_key, 1, nx=True, ex=10):
mode = brotli_.MODE_TEXT if response.content_type.startswith('text/') else brotli_.MODE_GENERIC