From 437b46f907576227338454ec5a302cbce2a30b9e Mon Sep 17 00:00:00 2001 From: echel0n Date: Sat, 15 Mar 2014 23:47:36 -0700 Subject: [PATCH] CacheHandler checks cached response to be OK before returning to requests HTTP handler now. --- lib/cachecontrol/controller.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/cachecontrol/controller.py b/lib/cachecontrol/controller.py index 029c5dc9..07ec8b84 100644 --- a/lib/cachecontrol/controller.py +++ b/lib/cachecontrol/controller.py @@ -151,9 +151,11 @@ class CacheController(object): fresh = (freshness_lifetime > current_age) if fresh: - # make sure we set the from_cache to true - resp.from_cache = True - return resp + if resp.ok: + # make sure we set the from_cache to true + resp.from_cache = True + return resp + return False # we're not fresh. If we don't have an Etag, clear it out if 'etag' not in resp.headers: @@ -216,7 +218,7 @@ class CacheController(object): # If the request is for our local cache, it means we should cache it elif self.cache_force: - resp.headers.update({'cache-control': 'max-age=21600, private'}) + resp.headers.update({'cache-control': 'max-age=900, private'}) self.cache.set(cache_url, resp) def update_cached_response(self, request, response):