_cache.py 786 B

1234567891011121314151617181920212223242526
  1. # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
  2. # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
  3. # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt
  4. from __future__ import annotations
  5. from typing import Any
  6. class CacheManager:
  7. """Manager of caches, to be used as a singleton."""
  8. def __init__(self) -> None:
  9. self.dict_caches: list[dict[Any, Any]] = []
  10. def clear_all_caches(self) -> None:
  11. """Clear all caches."""
  12. for dict_cache in self.dict_caches:
  13. dict_cache.clear()
  14. def add_dict_cache(self, cache: dict[Any, Any]) -> None:
  15. """Add a dictionary cache to the manager."""
  16. self.dict_caches.append(cache)
  17. CACHE_MANAGER = CacheManager()