From 0e435fb5f9a5542abe3929f13a9b91059f2d6976 Mon Sep 17 00:00:00 2001 From: Pedro Faustino Date: Mon, 24 Dec 2012 13:27:13 +0100 Subject: [PATCH] Add middleware support for the 'no-store' Cache-Control directive. --- scrapy/contrib/downloadermiddleware/httpcache.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scrapy/contrib/downloadermiddleware/httpcache.py b/scrapy/contrib/downloadermiddleware/httpcache.py index e88371747..b1da47586 100644 --- a/scrapy/contrib/downloadermiddleware/httpcache.py +++ b/scrapy/contrib/downloadermiddleware/httpcache.py @@ -83,11 +83,16 @@ class HttpCacheMiddleware(object): return response def is_cacheable_response(self, response): - return response.status not in self.ignore_http_codes + retval = response.status not in self.ignore_http_codes + if not self.use_dummy_cache and response.headers.has_key('cache-control'): + retval = retval and (response.headers['cache-control'].lower().find('no-store') == -1) + return retval def is_cacheable(self, request): - return urlparse_cached(request).scheme not in self.ignore_schemes - + retval = urlparse_cached(request).scheme not in self.ignore_schemes + if not self.use_dummy_cache and request.headers.has_key('cache-control'): + retval = retval and (request.headers['cache-control'].lower().find('no-store') == -1) + return retval class FilesystemCacheStorage(object):