Opt out of cache expiry for get_users_who_share_room_with_user (#10826)

* Allow LruCaches to opt out of time-based expiry
* Don't expire `get_users_who_share_room` & friends
This commit is contained in:
David Robertson 2021-09-22 14:21:58 +01:00 committed by GitHub
parent 80828eda06
commit 724aef9a87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 6 deletions

View file

@ -202,10 +202,11 @@ class _Node:
cache: "weakref.ReferenceType[LruCache]",
clock: Clock,
callbacks: Collection[Callable[[], None]] = (),
prune_unread_entries: bool = True,
):
self._list_node = ListNode.insert_after(self, root)
self._global_list_node = None
if USE_GLOBAL_LIST:
self._global_list_node: Optional[_TimedListNode] = None
if USE_GLOBAL_LIST and prune_unread_entries:
self._global_list_node = _TimedListNode.insert_after(self, GLOBAL_ROOT)
self._global_list_node.update_last_access(clock)
@ -314,6 +315,7 @@ class LruCache(Generic[KT, VT]):
metrics_collection_callback: Optional[Callable[[], None]] = None,
apply_cache_factor_from_config: bool = True,
clock: Optional[Clock] = None,
prune_unread_entries: bool = True,
):
"""
Args:
@ -427,7 +429,15 @@ class LruCache(Generic[KT, VT]):
self.len = synchronized(cache_len)
def add_node(key, value, callbacks: Collection[Callable[[], None]] = ()):
node = _Node(list_root, key, value, weak_ref_to_self, real_clock, callbacks)
node = _Node(
list_root,
key,
value,
weak_ref_to_self,
real_clock,
callbacks,
prune_unread_entries,
)
cache[key] = node
if size_callback: