Fix issue when API cache is turned off

This commit is contained in:
Ivan Kravets
2017-12-14 14:55:04 +02:00
parent 5c4b5c2270
commit 2522d19453

View File

@ -134,16 +134,10 @@ class ContentCache(object):
self._db_path = None self._db_path = None
self._lockfile = None self._lockfile = None
if not get_setting("enable_cache"):
return
self.cache_dir = cache_dir or join(util.get_home_dir(), ".cache") self.cache_dir = cache_dir or join(util.get_home_dir(), ".cache")
self._db_path = join(self.cache_dir, "db.data") self._db_path = join(self.cache_dir, "db.data")
def __enter__(self): def __enter__(self):
if not self._db_path or not isfile(self._db_path):
return self
self.delete() self.delete()
return self return self
@ -192,6 +186,8 @@ class ContentCache(object):
return data return data
def set(self, key, data, valid): def set(self, key, data, valid):
if not get_setting("enable_cache"):
return
cache_path = self.get_cache_path(key) cache_path = self.get_cache_path(key)
if isfile(cache_path): if isfile(cache_path):
self.delete(key) self.delete(key)
@ -220,6 +216,8 @@ class ContentCache(object):
def delete(self, keys=None): def delete(self, keys=None):
""" Keys=None, delete expired items """ """ Keys=None, delete expired items """
if not isfile(self._db_path):
return
if not keys: if not keys:
keys = [] keys = []
if not isinstance(keys, list): if not isinstance(keys, list):