mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-04 12:14:57 -04:00
Remove keylen
from LruCache
. (#9993)
`keylen` seems to be a thing that is frequently incorrectly set, and we don't really need it. The only time it was used was to figure out if we had removed a subtree in `del_multi`, which we can do better by changing `TreeCache.pop` to return a different type (`TreeCacheNode`). Commits should be independently reviewable.
This commit is contained in:
parent
316f89e87f
commit
c0df6bae06
11 changed files with 80 additions and 55 deletions
|
@ -34,7 +34,7 @@ from typing_extensions import Literal
|
|||
from synapse.config import cache as cache_config
|
||||
from synapse.util import caches
|
||||
from synapse.util.caches import CacheMetric, register_cache
|
||||
from synapse.util.caches.treecache import TreeCache
|
||||
from synapse.util.caches.treecache import TreeCache, iterate_tree_cache_entry
|
||||
|
||||
try:
|
||||
from pympler.asizeof import Asizer
|
||||
|
@ -160,7 +160,6 @@ class LruCache(Generic[KT, VT]):
|
|||
self,
|
||||
max_size: int,
|
||||
cache_name: Optional[str] = None,
|
||||
keylen: int = 1,
|
||||
cache_type: Type[Union[dict, TreeCache]] = dict,
|
||||
size_callback: Optional[Callable] = None,
|
||||
metrics_collection_callback: Optional[Callable[[], None]] = None,
|
||||
|
@ -173,9 +172,6 @@ class LruCache(Generic[KT, VT]):
|
|||
cache_name: The name of this cache, for the prometheus metrics. If unset,
|
||||
no metrics will be reported on this cache.
|
||||
|
||||
keylen: The length of the tuple used as the cache key. Ignored unless
|
||||
cache_type is `TreeCache`.
|
||||
|
||||
cache_type (type):
|
||||
type of underlying cache to be used. Typically one of dict
|
||||
or TreeCache.
|
||||
|
@ -403,7 +399,9 @@ class LruCache(Generic[KT, VT]):
|
|||
popped = cache.pop(key)
|
||||
if popped is None:
|
||||
return
|
||||
for leaf in enumerate_leaves(popped, keylen - len(cast(tuple, key))):
|
||||
# for each deleted node, we now need to remove it from the linked list
|
||||
# and run its callbacks.
|
||||
for leaf in iterate_tree_cache_entry(popped):
|
||||
delete_node(leaf)
|
||||
|
||||
@synchronized
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue