diff options
Diffstat (limited to 'gallery_dl/cache.py')
| -rw-r--r-- | gallery_dl/cache.py | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/gallery_dl/cache.py b/gallery_dl/cache.py index 6cde65d..3886091 100644 --- a/gallery_dl/cache.py +++ b/gallery_dl/cache.py @@ -57,7 +57,7 @@ class MemoryCacheDecorator(CacheDecorator): value, expires = self.cache[key] except KeyError: expires = 0 - if expires < timestamp: + if expires <= timestamp: value = self.func(*args, **kwargs) expires = timestamp + self.maxage self.cache[key] = value, expires @@ -189,25 +189,26 @@ def clear(): def _path(): - path = config.get(("cache",), "file", -1) - if path != -1: + path = config.get(("cache",), "file", util.SENTINEL) + if path is not util.SENTINEL: return util.expand_path(path) - if os.name == "nt": - import tempfile - return os.path.join(tempfile.gettempdir(), ".gallery-dl.cache") + if util.WINDOWS: + cachedir = os.environ.get("APPDATA", "~") + else: + cachedir = os.environ.get("XDG_CACHE_HOME", "~/.cache") - cachedir = util.expand_path(os.path.join( - os.environ.get("XDG_CACHE_HOME", "~/.cache"), "gallery-dl")) + cachedir = util.expand_path(os.path.join(cachedir, "gallery-dl")) os.makedirs(cachedir, exist_ok=True) return os.path.join(cachedir, "cache.sqlite3") try: dbfile = _path() - if os.name != "nt": - # restrict access permissions for new db files - os.close(os.open(dbfile, os.O_CREAT | os.O_RDONLY, 0o600)) + + # restrict access permissions for new db files + os.close(os.open(dbfile, os.O_CREAT | os.O_RDONLY, 0o600)) + DatabaseCacheDecorator.db = sqlite3.connect( dbfile, timeout=30, check_same_thread=False) except (OSError, TypeError, sqlite3.OperationalError): |
