feat: clean and clear methods for the cache

This commit is contained in:
Hazel 2024-01-22 09:36:14 +01:00
parent 2d4ba50b57
commit fba9c31c50
3 changed files with 41 additions and 1 deletions

View File

@ -4,12 +4,13 @@ import sys
from .utils.shared import DEBUG, DEBUG_LOGGING
from .utils.config import logging_settings, main_settings, read_config
read_config()
from . import cli
if DEBUG:
import sys
sys.setrecursionlimit(100)

View File

@ -79,6 +79,18 @@ def cli():
action="store_true"
)
parser.add_argument(
"--clear-cache",
help="Deletes the cache.",
action="store_true"
)
parser.add_argument(
"--clean-cache",
help="Deletes the outdated cache. (all expired cached files, and not indexed files)",
action="store_true"
)
arguments = parser.parse_args()
if arguments.verbose or arguments.test:
@ -112,6 +124,12 @@ def cli():
if arguments.frontend:
cli.set_frontend(silent=False)
if arguments.clear_cache:
cli.clear_cache()
if arguments.clean_cache:
cli.clean_cache()
# getting the genre
genre: str = arguments.genre
if arguments.test:

View File

@ -0,0 +1,21 @@
from logging import getLogger
from ...connection.cache import Cache
def clear_cache():
"""
Deletes the cache.
:return:
"""
Cache("main", getLogger("cache")).clear()
def clean_cache():
"""
Deletes the outdated cache. (all expired cached files, and not indexed files)
:return:
"""
Cache("main", getLogger("cache")).clean()