diff --git a/gallery_dl/__init__.py b/gallery_dl/__init__.py index 5bf229a3..7d64c91e 100644 --- a/gallery_dl/__init__.py +++ b/gallery_dl/__init__.py @@ -186,7 +186,7 @@ def main(): elif args.clear_cache: from . import cache log = logging.getLogger("cache") - cnt = cache.clear() + cnt = cache.clear(args.clear_cache) if cnt is None: log.error("Database file not available") diff --git a/gallery_dl/cache.py b/gallery_dl/cache.py index a874f63b..5ab68bf1 100644 --- a/gallery_dl/cache.py +++ b/gallery_dl/cache.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2016-2020 Mike Fährmann +# Copyright 2016-2021 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -168,24 +168,33 @@ def cache(maxage=3600, keyarg=None): return wrap -def clear(): - """Delete all database entries""" +def clear(module="all"): + """Delete database entries for 'module'""" db = DatabaseCacheDecorator.db + if not db: + return None - if db: - rowcount = 0 - cursor = db.cursor() - try: + rowcount = 0 + cursor = db.cursor() + module = module.lower() + + try: + if module == "all": cursor.execute("DELETE FROM data") - except sqlite3.OperationalError: - pass # database is not initialized, can't be modified, etc. else: - rowcount = cursor.rowcount - db.commit() + cursor.execute( + "DELETE FROM data " + "WHERE key LIKE 'gallery_dl.extractor.' || ? || '.%'", + (module,) + ) + except sqlite3.OperationalError: + pass # database is not initialized, can't be modified, etc. + else: + rowcount = cursor.rowcount + db.commit() + if rowcount: cursor.execute("VACUUM") - return rowcount - - return None + return rowcount def _path(): diff --git a/gallery_dl/option.py b/gallery_dl/option.py index 3e585fe0..6018542e 100644 --- a/gallery_dl/option.py +++ b/gallery_dl/option.py @@ -114,7 +114,7 @@ def build_parser(): ) general.add_argument( "--clear-cache", - dest="clear_cache", action="store_true", + dest="clear_cache", metavar="MODULE", nargs="?", const="all", help="Delete all cached login sessions, cookies, etc.", )