Fixed typo in TVDB Api code

Updated cache handler code
This commit is contained in:
echel0n 2014-03-27 15:39:54 -07:00
parent 6a1ccef8d9
commit 3db51ef268
3 changed files with 19 additions and 10 deletions

View file

@ -200,12 +200,17 @@ class CacheController(object):
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
if self.cache_all:
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 = {'Cache-Control': 'public,max-age=%d' % int(3600),
'Expires': expires}
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

View file

@ -428,13 +428,15 @@ class Tvdb:
if cache is True:
self.config['cache_enabled'] = True
self.sess = cachecontrol.CacheControl(requests.Session(),
cache=caches.FileCache(self._getTempDir()), cache_all=True)
cache_all=True,
cache=caches.FileCache(self._getTempDir()))
elif cache is False:
self.config['cache_enabled'] = False
elif isinstance(cache, basestring):
self.config['cache_enabled'] = True
self.sess = cachecontrol.CacheControl(requests.Session(),
cache=caches.FileCache(cache), cache_all=True)
cache_all=True,
cache=caches.FileCache(cache))
else:
raise ValueError("Invalid value for Cache %r (type was %s)" % (cache, type(cache)))
@ -537,7 +539,7 @@ class Tvdb:
# get response from TVDB
if self.config['cache_enabled']:
resp = self.sess.get(url, params=sorted(params))
resp = self.sess.get(url, params=params)
else:
resp = requests.get(url, params=params)

View file

@ -271,13 +271,15 @@ class TVRage:
if cache is True:
self.config['cache_enabled'] = True
self.sess = cachecontrol.CacheControl(requests.Session(),
cache=caches.FileCache(self._getTempDir()), cache_all=True)
cache_all=True,
cache=caches.FileCache(self._getTempDir()))
elif cache is False:
self.config['cache_enabled'] = False
elif isinstance(cache, basestring):
self.config['cache_enabled'] = True
self.sess = cachecontrol.CacheControl(requests.Session(),
cache=caches.FileCache(cache), cache_all=True)
cache_all=True,
cache=caches.FileCache(cache))
else:
raise ValueError("Invalid value for Cache %r (type was %s)" % (cache, type(cache)))