@staticmethoddef_predicate(member:Callable)->bool:"""Check if the method is a cached method"""ifgetattr(member,"__name__","_").startswith("_"):returnFalsereturnbool(hasattr(member,"cache"))ifinspect.ismethod(member)elseFalse
[docs]defget_all_methods(self)->Iterator[Callable]:"""Get all methods of the class"""return[_callableformember,_callableininspect.getmembers(self,predicate=self._predicate)]
[docs]asyncdefinvalidate_cache(self,*methods:Callable)->None:"""Invalidate the cache for the given methods if not specify all"""ifmethods:awaitinvalidate_cache_multi(methods,self)else:awaitinvalidate_cache_multi(self.get_all_methods(),self)
[docs]asyncdefupdate_cache(self,*pairs:tuple[Callable,Any])->None:"""Update the cache for the specified method"""awaitupdate_cache_multi(pairs,self)