diff options
| author | 2020-06-01 23:11:37 -0400 | |
|---|---|---|
| committer | 2020-06-01 23:11:37 -0400 | |
| commit | a70a3246927b72f1ded37acd55ee719515441b5b (patch) | |
| tree | 57f0d3ab0b1387b665325f42a24b8aab63cbce07 /gallery_dl/cache.py | |
| parent | 90e50db2e3c38f523bb5195d295290b06e5cedb0 (diff) | |
New upstream version 1.14.0.upstream/1.14.0
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): |
