mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2025-06-20 06:34:10 -04:00
Add cache invalidation across workers to module API (#13667)
Signed-off-by: Mathieu Velten <mathieuv@matrix.org>
This commit is contained in:
parent
16e1a9d9a7
commit
6bd8763804
7 changed files with 153 additions and 21 deletions
|
@ -33,7 +33,7 @@ from synapse.storage.database import (
|
|||
)
|
||||
from synapse.storage.engines import PostgresEngine
|
||||
from synapse.storage.util.id_generators import MultiWriterIdGenerator
|
||||
from synapse.util.caches.descriptors import _CachedFunction
|
||||
from synapse.util.caches.descriptors import CachedFunction
|
||||
from synapse.util.iterutils import batch_iter
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -269,9 +269,7 @@ class CacheInvalidationWorkerStore(SQLBaseStore):
|
|||
return
|
||||
|
||||
cache_func.invalidate(keys)
|
||||
await self.db_pool.runInteraction(
|
||||
"invalidate_cache_and_stream",
|
||||
self._send_invalidation_to_replication,
|
||||
await self.send_invalidation_to_replication(
|
||||
cache_func.__name__,
|
||||
keys,
|
||||
)
|
||||
|
@ -279,7 +277,7 @@ class CacheInvalidationWorkerStore(SQLBaseStore):
|
|||
def _invalidate_cache_and_stream(
|
||||
self,
|
||||
txn: LoggingTransaction,
|
||||
cache_func: _CachedFunction,
|
||||
cache_func: CachedFunction,
|
||||
keys: Tuple[Any, ...],
|
||||
) -> None:
|
||||
"""Invalidates the cache and adds it to the cache stream so slaves
|
||||
|
@ -293,7 +291,7 @@ class CacheInvalidationWorkerStore(SQLBaseStore):
|
|||
self._send_invalidation_to_replication(txn, cache_func.__name__, keys)
|
||||
|
||||
def _invalidate_all_cache_and_stream(
|
||||
self, txn: LoggingTransaction, cache_func: _CachedFunction
|
||||
self, txn: LoggingTransaction, cache_func: CachedFunction
|
||||
) -> None:
|
||||
"""Invalidates the entire cache and adds it to the cache stream so slaves
|
||||
will know to invalidate their caches.
|
||||
|
@ -334,6 +332,16 @@ class CacheInvalidationWorkerStore(SQLBaseStore):
|
|||
txn, CURRENT_STATE_CACHE_NAME, [room_id]
|
||||
)
|
||||
|
||||
async def send_invalidation_to_replication(
|
||||
self, cache_name: str, keys: Optional[Collection[Any]]
|
||||
) -> None:
|
||||
await self.db_pool.runInteraction(
|
||||
"send_invalidation_to_replication",
|
||||
self._send_invalidation_to_replication,
|
||||
cache_name,
|
||||
keys,
|
||||
)
|
||||
|
||||
def _send_invalidation_to_replication(
|
||||
self, txn: LoggingTransaction, cache_name: str, keys: Optional[Iterable[Any]]
|
||||
) -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue