mirror of
https://mau.dev/maunium/synapse.git
synced 2024-08-28 13:11:56 +00:00
Add comments
This commit is contained in:
parent
7c7706f42b
commit
9a0d783c11
@ -154,11 +154,18 @@ class LruCache(object):
|
|||||||
def cache_set(key, value, callbacks=[]):
|
def cache_set(key, value, callbacks=[]):
|
||||||
node = cache.get(key, None)
|
node = cache.get(key, None)
|
||||||
if node is not None:
|
if node is not None:
|
||||||
|
# We sometimes store large objects, e.g. dicts, which cause
|
||||||
|
# the inequality check to take a long time. So let's only do
|
||||||
|
# the check if we have some callbacks to call.
|
||||||
if node.callbacks and value != node.value:
|
if node.callbacks and value != node.value:
|
||||||
for cb in node.callbacks:
|
for cb in node.callbacks:
|
||||||
cb()
|
cb()
|
||||||
node.callbacks.clear()
|
node.callbacks.clear()
|
||||||
|
|
||||||
|
# We don't bother to protect this by value != node.value as
|
||||||
|
# generally size_callback will be cheap compared with equality
|
||||||
|
# checks. (For example, taking the size of two dicts is quicker
|
||||||
|
# than comparing them for equality.)
|
||||||
if size_callback:
|
if size_callback:
|
||||||
cached_cache_len[0] -= size_callback(node.value)
|
cached_cache_len[0] -= size_callback(node.value)
|
||||||
cached_cache_len[0] += size_callback(value)
|
cached_cache_len[0] += size_callback(value)
|
||||||
|
Loading…
Reference in New Issue
Block a user