mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-01 16:56:04 -04:00
Allow streaming cache invalidate all to workers. (#6749)
This commit is contained in:
parent
2093f83ea0
commit
5d7a6ad223
6 changed files with 69 additions and 15 deletions
|
@ -17,6 +17,7 @@
|
|||
import logging
|
||||
import random
|
||||
from abc import ABCMeta
|
||||
from typing import Any, Optional
|
||||
|
||||
from six import PY2
|
||||
from six.moves import builtins
|
||||
|
@ -26,7 +27,7 @@ from canonicaljson import json
|
|||
from synapse.storage.database import LoggingTransaction # noqa: F401
|
||||
from synapse.storage.database import make_in_list_sql_clause # noqa: F401
|
||||
from synapse.storage.database import Database
|
||||
from synapse.types import get_domain_from_id
|
||||
from synapse.types import Collection, get_domain_from_id
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -63,17 +64,24 @@ class SQLBaseStore(metaclass=ABCMeta):
|
|||
self._attempt_to_invalidate_cache("get_room_summary", (room_id,))
|
||||
self._attempt_to_invalidate_cache("get_current_state_ids", (room_id,))
|
||||
|
||||
def _attempt_to_invalidate_cache(self, cache_name, key):
|
||||
def _attempt_to_invalidate_cache(
|
||||
self, cache_name: str, key: Optional[Collection[Any]]
|
||||
):
|
||||
"""Attempts to invalidate the cache of the given name, ignoring if the
|
||||
cache doesn't exist. Mainly used for invalidating caches on workers,
|
||||
where they may not have the cache.
|
||||
|
||||
Args:
|
||||
cache_name (str)
|
||||
key (tuple)
|
||||
cache_name
|
||||
key: Entry to invalidate. If None then invalidates the entire
|
||||
cache.
|
||||
"""
|
||||
|
||||
try:
|
||||
getattr(self, cache_name).invalidate(key)
|
||||
if key is None:
|
||||
getattr(self, cache_name).invalidate_all()
|
||||
else:
|
||||
getattr(self, cache_name).invalidate(tuple(key))
|
||||
except AttributeError:
|
||||
# We probably haven't pulled in the cache in this worker,
|
||||
# which is fine.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue