1
0

DBG cache

This commit is contained in:
Olivier Wilkinson (reivilibre)
2022-07-05 12:23:29 +01:00
parent 7fd218ad8b
commit 5af3ce8bf8
3 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -476,7 +476,7 @@ class RoomMemberWorkerStore(EventsWorkerStore):
return results_dict.get("membership"), results_dict.get("event_id")
@cached(max_entries=500000, iterable=True, prune_unread_entries=False)
@cached(max_entries=500000, iterable=True, prune_unread_entries=False, debug_invalidations=True)
async def get_rooms_for_user_with_stream_ordering(
self, user_id: str
) -> FrozenSet[GetRoomsForUserWithStreamOrdering]:
+7
View File
@@ -15,6 +15,7 @@
# limitations under the License.
import enum
import logging
import threading
from typing import (
Callable,
@@ -66,6 +67,7 @@ class DeferredCache(Generic[KT, VT]):
"cache",
"thread",
"_pending_deferred_cache",
"debug_invalidations"
)
def __init__(
@@ -76,6 +78,7 @@ class DeferredCache(Generic[KT, VT]):
iterable: bool = False,
apply_cache_factor_from_config: bool = True,
prune_unread_entries: bool = True,
debug_invalidations: bool = False,
):
"""
Args:
@@ -119,6 +122,7 @@ class DeferredCache(Generic[KT, VT]):
)
self.thread: Optional[threading.Thread] = None
self.debug_invalidations = debug_invalidations
@property
def max_entries(self) -> int:
@@ -310,6 +314,9 @@ class DeferredCache(Generic[KT, VT]):
self.check_thread()
self.cache.del_multi(key)
if self.debug_invalidations:
logging.debug("Invalidating key %r in cache %s", key)
# if we have a pending lookup for this key, remove it from the
# _pending_deferred_cache, which will (a) stop it being returned
# for future queries and (b) stop it being persisted as a proper entry
+5
View File
@@ -301,6 +301,7 @@ class DeferredCacheDescriptor(_CacheDescriptorBase):
cache_context: bool = False,
iterable: bool = False,
prune_unread_entries: bool = True,
debug_invalidations: bool = False
):
super().__init__(
orig,
@@ -318,6 +319,7 @@ class DeferredCacheDescriptor(_CacheDescriptorBase):
self.tree = tree
self.iterable = iterable
self.prune_unread_entries = prune_unread_entries
self.debug_invalidations = debug_invalidations
def __get__(self, obj: Optional[Any], owner: Optional[Type]) -> Callable[..., Any]:
cache: DeferredCache[CacheKey, Any] = DeferredCache(
@@ -326,6 +328,7 @@ class DeferredCacheDescriptor(_CacheDescriptorBase):
tree=self.tree,
iterable=self.iterable,
prune_unread_entries=self.prune_unread_entries,
debug_invalidations=self.debug_invalidations,
)
get_cache_key = self.cache_key_builder
@@ -577,6 +580,7 @@ def cached(
cache_context: bool = False,
iterable: bool = False,
prune_unread_entries: bool = True,
debug_invalidations: bool = False,
) -> Callable[[F], _CachedFunction[F]]:
func = lambda orig: DeferredCacheDescriptor(
orig,
@@ -587,6 +591,7 @@ def cached(
cache_context=cache_context,
iterable=iterable,
prune_unread_entries=prune_unread_entries,
debug_invalidations=debug_invalidations
)
return cast(Callable[[F], _CachedFunction[F]], func)