Replace DeferredCache with LruCache where possible (#8563)

Most of these uses don't need a full-blown DeferredCache; LruCache is lighter and more appropriate.
This commit is contained in:
Richard van der Hoff 2020-10-19 12:20:29 +01:00 committed by GitHub
parent 79c1f973ce
commit 97647b33c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 27 deletions

View file

@ -42,8 +42,8 @@ from synapse.storage.database import DatabasePool
from synapse.storage.engines import PostgresEngine
from synapse.storage.util.id_generators import MultiWriterIdGenerator, StreamIdGenerator
from synapse.types import Collection, get_domain_from_id
from synapse.util.caches.deferred_cache import DeferredCache
from synapse.util.caches.descriptors import cached
from synapse.util.caches.lrucache import LruCache
from synapse.util.iterutils import batch_iter
from synapse.util.metrics import Measure
@ -146,11 +146,10 @@ class EventsWorkerStore(SQLBaseStore):
self._cleanup_old_transaction_ids,
)
self._get_event_cache = DeferredCache(
"*getEvent*",
self._get_event_cache = LruCache(
cache_name="*getEvent*",
keylen=3,
max_entries=hs.config.caches.event_cache_size,
apply_cache_factor_from_config=False,
max_size=hs.config.caches.event_cache_size,
)
self._event_fetch_lock = threading.Condition()
@ -749,7 +748,7 @@ class EventsWorkerStore(SQLBaseStore):
event=original_ev, redacted_event=redacted_event
)
self._get_event_cache.prefill((event_id,), cache_entry)
self._get_event_cache.set((event_id,), cache_entry)
result_map[event_id] = cache_entry
return result_map