You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
680 B
30 lines
680 B
from pathlib import Path
|
|
import atexit
|
|
|
|
from tibi_hardlinks.config import CACHE_DIR
|
|
|
|
import shelve
|
|
|
|
CACHE_FILE = (Path(CACHE_DIR) / "cache").absolute()
|
|
|
|
|
|
class CacheManager:
|
|
def __init__(self):
|
|
self.tibi_cache = None
|
|
|
|
def open_cache(self):
|
|
self.tibi_cache = shelve.open(str(CACHE_FILE), writeback=True)
|
|
atexit.register(self.tibi_cache.close)
|
|
|
|
def invalidate_all(self):
|
|
self.tibi_cache.close()
|
|
CACHE_FILE.unlink()
|
|
self.open_cache()
|
|
|
|
def invalidate_already_processed(self):
|
|
self.tibi_cache["already_processed"] = set()
|
|
self.tibi_cache.sync()
|
|
|
|
|
|
cache_manager = CacheManager()
|
|
cache_manager.open_cache()
|