feat: cache cli options

This commit is contained in:
Hazel 2024-01-29 08:39:57 +01:00
parent 2a77f75e6f
commit 0fedfd880e
3 changed files with 12 additions and 2 deletions

View File

@ -125,10 +125,12 @@ def cli():
cli.set_frontend(silent=False) cli.set_frontend(silent=False)
if arguments.clear_cache: if arguments.clear_cache:
cli.clear_cache() from .cli.options import cache
cache.clear_cache()
if arguments.clean_cache: if arguments.clean_cache:
cli.clean_cache() from .cli.options import cache
cache.clean_cache()
# getting the genre # getting the genre
genre: str = arguments.genre genre: str = arguments.genre

View File

@ -1,8 +1,10 @@
from logging import getLogger from logging import getLogger
from ..utils import cli_function
from ...connection.cache import Cache from ...connection.cache import Cache
@cli_function
def clear_cache(): def clear_cache():
""" """
Deletes the cache. Deletes the cache.
@ -10,8 +12,10 @@ def clear_cache():
""" """
Cache("main", getLogger("cache")).clear() Cache("main", getLogger("cache")).clear()
print("Cleared cache")
@cli_function
def clean_cache(): def clean_cache():
""" """
Deletes the outdated cache. (all expired cached files, and not indexed files) Deletes the outdated cache. (all expired cached files, and not indexed files)
@ -19,3 +23,4 @@ def clean_cache():
""" """
Cache("main", getLogger("cache")).clean() Cache("main", getLogger("cache")).clean()
print("Cleaned cache")

View File

@ -145,6 +145,9 @@ class Cache:
keep = set() keep = set()
for ca in self.cached_attributes.copy(): for ca in self.cached_attributes.copy():
if ca.name == "":
continue
file = Path(self._dir, ca.module, ca.name) file = Path(self._dir, ca.module, ca.name)
if not ca.is_valid: if not ca.is_valid: