mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2025-08-03 23:04:12 -04:00
Extend ResponseCache
to pass a context object into the callback (#10157)
This is the first of two PRs which seek to address #8518. This first PR lays the groundwork by extending ResponseCache; a second PR (#10158) will update the SyncHandler to actually use it, and fix the bug. The idea here is that we allow the callback given to ResponseCache.wrap to decide whether its result should be cached or not. We do that by (optionally) passing a ResponseCacheContext into it, which it can modify.
This commit is contained in:
parent
13577aa55e
commit
d7808a2dde
5 changed files with 146 additions and 37 deletions
|
@ -285,7 +285,7 @@ class ReplicationEndpoint(metaclass=abc.ABCMeta):
|
|||
self.__class__.__name__,
|
||||
)
|
||||
|
||||
def _check_auth_and_handle(self, request, **kwargs):
|
||||
async def _check_auth_and_handle(self, request, **kwargs):
|
||||
"""Called on new incoming requests when caching is enabled. Checks
|
||||
if there is a cached response for the request and returns that,
|
||||
otherwise calls `_handle_request` and caches its response.
|
||||
|
@ -300,8 +300,8 @@ class ReplicationEndpoint(metaclass=abc.ABCMeta):
|
|||
if self.CACHE:
|
||||
txn_id = kwargs.pop("txn_id")
|
||||
|
||||
return self.response_cache.wrap(
|
||||
return await self.response_cache.wrap(
|
||||
txn_id, self._handle_request, request, **kwargs
|
||||
)
|
||||
|
||||
return self._handle_request(request, **kwargs)
|
||||
return await self._handle_request(request, **kwargs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue