mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 11:56:07 -04:00
Cache federation state responses
This commit is contained in:
parent
e9e3eaa67d
commit
248e6770ca
5 changed files with 61 additions and 33 deletions
|
@ -24,9 +24,12 @@ class ResponseCache(object):
|
|||
used rather than trying to compute a new response.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, hs, timeout_ms=0):
|
||||
self.pending_result_cache = {} # Requests that haven't finished yet.
|
||||
|
||||
self.clock = hs.get_clock()
|
||||
self.timeout_sec = timeout_ms / 1000.
|
||||
|
||||
def get(self, key):
|
||||
result = self.pending_result_cache.get(key)
|
||||
if result is not None:
|
||||
|
@ -39,7 +42,13 @@ class ResponseCache(object):
|
|||
self.pending_result_cache[key] = result
|
||||
|
||||
def remove(r):
|
||||
self.pending_result_cache.pop(key, None)
|
||||
if self.timeout_sec:
|
||||
self.clock.call_later(
|
||||
self.timeout_sec,
|
||||
self.pending_result_cache.pop, key, None,
|
||||
)
|
||||
else:
|
||||
self.pending_result_cache.pop(key, None)
|
||||
return r
|
||||
|
||||
result.addBoth(remove)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue