Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. from caching.errors import WorkerCacheError
  2. from caching.worker import Worker
  3.  
  4.  
  5. class CacheManager:
  6.  
  7. _singleton = None
  8.  
  9. def __new__(cls, *args, **kwargs):
  10. if not cls._singleton:
  11. cls._singleton = super(CacheManager, cls).__new__(cls, *args, **kwargs)
  12. return cls._singleton
  13.  
  14. def __init__(self):
  15. """
  16. The constructor for the CacheManager class.
  17. """
  18. self.worker = None
  19.  
  20. @property
  21. def cache_path(self):
  22. """
  23. Dynamic property.
  24.  
  25. :return: if self.worker => self.worker.base_dir else None
  26. """
  27. if self.worker:
  28. return self.worker.base_dir
  29. else:
  30. return None
  31.  
  32. def create_cache(self):
  33. """
  34. Deletes the old worker and creates a new one.
  35.  
  36. :return: None
  37. """
  38. del self.worker
  39. self.worker = Worker()
  40.  
  41. def wipe_cache(self):
  42. """
  43. Deletes the current worker.
  44.  
  45. :return: None
  46. """
  47. del self.worker
  48. self.worker = None
  49.  
  50. def __enter__(self):
  51. self.create_cache()
  52.  
  53. def __exit__(self, type, value, traceback):
  54. self.wipe_cache()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement