mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-04 01:34:47 -04:00
Add cache invalidation across workers to module API (#13667)
Signed-off-by: Mathieu Velten <mathieuv@matrix.org>
This commit is contained in:
parent
16e1a9d9a7
commit
6bd8763804
7 changed files with 153 additions and 21 deletions
|
@ -53,7 +53,7 @@ CacheKey = Union[Tuple, Any]
|
|||
F = TypeVar("F", bound=Callable[..., Any])
|
||||
|
||||
|
||||
class _CachedFunction(Generic[F]):
|
||||
class CachedFunction(Generic[F]):
|
||||
invalidate: Any = None
|
||||
invalidate_all: Any = None
|
||||
prefill: Any = None
|
||||
|
@ -242,7 +242,7 @@ class LruCacheDescriptor(_CacheDescriptorBase):
|
|||
|
||||
return ret2
|
||||
|
||||
wrapped = cast(_CachedFunction, _wrapped)
|
||||
wrapped = cast(CachedFunction, _wrapped)
|
||||
wrapped.cache = cache
|
||||
obj.__dict__[self.name] = wrapped
|
||||
|
||||
|
@ -363,7 +363,7 @@ class DeferredCacheDescriptor(_CacheDescriptorBase):
|
|||
|
||||
return make_deferred_yieldable(ret)
|
||||
|
||||
wrapped = cast(_CachedFunction, _wrapped)
|
||||
wrapped = cast(CachedFunction, _wrapped)
|
||||
|
||||
if self.num_args == 1:
|
||||
assert not self.tree
|
||||
|
@ -572,7 +572,7 @@ def cached(
|
|||
iterable: bool = False,
|
||||
prune_unread_entries: bool = True,
|
||||
name: Optional[str] = None,
|
||||
) -> Callable[[F], _CachedFunction[F]]:
|
||||
) -> Callable[[F], CachedFunction[F]]:
|
||||
func = lambda orig: DeferredCacheDescriptor(
|
||||
orig,
|
||||
max_entries=max_entries,
|
||||
|
@ -585,7 +585,7 @@ def cached(
|
|||
name=name,
|
||||
)
|
||||
|
||||
return cast(Callable[[F], _CachedFunction[F]], func)
|
||||
return cast(Callable[[F], CachedFunction[F]], func)
|
||||
|
||||
|
||||
def cachedList(
|
||||
|
@ -594,7 +594,7 @@ def cachedList(
|
|||
list_name: str,
|
||||
num_args: Optional[int] = None,
|
||||
name: Optional[str] = None,
|
||||
) -> Callable[[F], _CachedFunction[F]]:
|
||||
) -> Callable[[F], CachedFunction[F]]:
|
||||
"""Creates a descriptor that wraps a function in a `DeferredCacheListDescriptor`.
|
||||
|
||||
Used to do batch lookups for an already created cache. One of the arguments
|
||||
|
@ -631,7 +631,7 @@ def cachedList(
|
|||
name=name,
|
||||
)
|
||||
|
||||
return cast(Callable[[F], _CachedFunction[F]], func)
|
||||
return cast(Callable[[F], CachedFunction[F]], func)
|
||||
|
||||
|
||||
def _get_cache_key_builder(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue