mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-01 00:43:37 +00:00
Move some code around in our cache handler for better parsing and accuracy of caching
This commit is contained in:
parent
84e75ec59d
commit
1bb9413b19
1 changed files with 11 additions and 14 deletions
|
@ -185,6 +185,17 @@ class CacheController(object):
|
|||
if resp.status_code not in [200, 203]:
|
||||
return
|
||||
|
||||
# If we want to cache sites not setup with cache headers then add the proper headers and keep the response
|
||||
if self.cache_all and getattr(resp.headers, 'cache-control', None) is None:
|
||||
headers = {'Cache-Control': 'public,max-age=%d' % int(900)}
|
||||
resp.headers.update(headers)
|
||||
|
||||
if getattr(resp.headers, 'expires', None) is None:
|
||||
expires = datetime.datetime.utcnow() + datetime.timedelta(days=(1))
|
||||
expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
||||
headers = {'Expires': expires}
|
||||
resp.headers.update(headers)
|
||||
|
||||
cc_req = self.parse_cache_control(request.headers)
|
||||
cc = self.parse_cache_control(resp.headers)
|
||||
|
||||
|
@ -199,20 +210,6 @@ class CacheController(object):
|
|||
if self.cache_etags and 'etag' in resp.headers:
|
||||
self.cache.set(cache_url, resp)
|
||||
|
||||
# If we want to cache sites not setup with cache headers then add the proper headers and keep the response
|
||||
elif self.cache_all and getattr(resp.headers, 'cache-control', None) is None:
|
||||
headers = {'Cache-Control': 'public,max-age=%d' % int(3600)}
|
||||
resp.headers.update(headers)
|
||||
|
||||
if getattr(resp.headers, 'expires', None) is None:
|
||||
expires = datetime.datetime.utcnow() + datetime.timedelta(days=(25 * 365))
|
||||
expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
||||
headers = {'Expires': expires}
|
||||
resp.headers.update(headers)
|
||||
|
||||
# Add resp to cache
|
||||
self.cache.set(cache_url, resp)
|
||||
|
||||
# Add to the cache if the response headers demand it. If there
|
||||
# is no date header then we can't do anything about expiring
|
||||
# the cache.
|
||||
|
|
Loading…
Reference in a new issue