Add clean_cache method

master
Felix Stupp 4 years ago
parent a4c464decb
commit 38fea4eaf4
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -59,6 +59,17 @@ class ApplicationCache():
def gen_key(cls, cache_id: str, args: list, kwargs: dict) -> str:
return cls.get_hash(args, kwargs, cache_id)
def clean_cache(self, max_age: int = None) -> int:
max_age = max_age or self.default_max_age
cleaned_count = 0
for cache_path in self.cache_dir.iterdir():
if cache_path.is_file():
cache_stat = cache_path.stat()
if cache_stat.st_mtime + max_age <= time.time():
cache_path.unlink()
cleaned_count += 1
return cleaned_count
def compress(self, data: str) -> bytes:
bin_data = data.encode(self.encoding)
if self.compress_data and len(bin_data) > self.compress_threshold:

Loading…
Cancel
Save