class ResolutionCache: """ Local cache of resolutions. Args: context: An environment variable could have different meanings in different contexts. For example, path: Path to cache. Uses the user's home directory by default. """ def __init__( self, context: str, logger: Optional[Logger] = None, path: Optional[Path] = None, ) -> None: self.logger = logger or get_logger() self.context = context self.path = path or Path.home().absolute().joinpath(".wevcache") self.resolutions: Dict[Tuple[str, ...], Dict[str, Any]] = {} self.logger.debug( 'ResolutionCache: context="%s" path="%s"', self.context, self.path, ) def get(self, names: Tuple[str, ...]) -> Optional[Resolution]: """ Gets a cached resolution, or `None` if not cached. """ if store := self.resolutions.get(names, None): if values := store.get("values", None): if isinstance(values, list): store["values"] = tuple(cast(List[str], values)) return Resolution(store=store)
def resolution(self) -> Optional[Resolution]: """ Gets the resolution. """ if store := self.store.get("resolution", None): return Resolution(store=store)