mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 11:26:09 -04:00
Add a cache for get_current_state with state_key
This commit is contained in:
parent
e89ca34e0e
commit
d61ce3f670
5 changed files with 46 additions and 2 deletions
|
@ -20,7 +20,6 @@ import threading
|
|||
|
||||
class LruCache(object):
|
||||
"""Least-recently-used cache."""
|
||||
# TODO(mjark) Add mutex for linked list for thread safety.
|
||||
def __init__(self, max_size):
|
||||
cache = {}
|
||||
list_root = []
|
||||
|
@ -105,6 +104,12 @@ class LruCache(object):
|
|||
else:
|
||||
return default
|
||||
|
||||
@synchronized
|
||||
def cache_clear():
|
||||
list_root[NEXT] = list_root
|
||||
list_root[PREV] = list_root
|
||||
cache.clear()
|
||||
|
||||
@synchronized
|
||||
def cache_len():
|
||||
return len(cache)
|
||||
|
@ -120,6 +125,7 @@ class LruCache(object):
|
|||
self.pop = cache_pop
|
||||
self.len = cache_len
|
||||
self.contains = cache_contains
|
||||
self.clear = cache_clear
|
||||
|
||||
def __getitem__(self, key):
|
||||
result = self.get(key, self.sentinel)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue