Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from caching.errors import WorkerCacheError
- from caching.worker import Worker
- class CacheManager:
- _singleton = None
- def __new__(cls, *args, **kwargs):
- if not cls._singleton:
- cls._singleton = super(CacheManager, cls).__new__(cls, *args, **kwargs)
- return cls._singleton
- def __init__(self):
- """
- The constructor for the CacheManager class.
- """
- self.worker = None
- @property
- def cache_path(self):
- """
- Dynamic property.
- :return: if self.worker => self.worker.base_dir else None
- """
- if self.worker:
- return self.worker.base_dir
- else:
- return None
- def create_cache(self):
- """
- Deletes the old worker and creates a new one.
- :return: None
- """
- del self.worker
- self.worker = Worker()
- def wipe_cache(self):
- """
- Deletes the current worker.
- :return: None
- """
- del self.worker
- self.worker = None
- def __enter__(self):
- self.create_cache()
- def __exit__(self, type, value, traceback):
- self.wipe_cache()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement