Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
326a175
Make DictionaryCache have better expiry properties
erikjohnston Jul 15, 2022
40a8fba
Newsfile
erikjohnston Jul 15, 2022
a22716c
Fix literal
erikjohnston Jul 15, 2022
f046366
Fix test
erikjohnston Jul 15, 2022
602a81f
don't update access
erikjohnston Jul 15, 2022
23c2f39
Fix mypy
erikjohnston Jul 15, 2022
cad555f
Better stuff
erikjohnston Jul 15, 2022
7aceec3
Fix up
erikjohnston Jul 15, 2022
057ae8b
Comments
erikjohnston Jul 17, 2022
7f7b36d
Comment LruCache
erikjohnston Jul 18, 2022
462db2a
Comment LruCache
erikjohnston Jul 18, 2022
129691f
Comment TreeCache
erikjohnston Jul 18, 2022
45d0dce
Merge branch 'develop' into erikj/dict_cache
erikjohnston Jul 18, 2022
ca8e1af
Update synapse/util/caches/dictionary_cache.py
erikjohnston Jul 19, 2022
e4723df
Update synapse/util/caches/lrucache.py
erikjohnston Jul 19, 2022
a74baa6
Split out code to separate method
erikjohnston Jul 19, 2022
a9ebcd2
Mark DictionaryEntry as frozen
erikjohnston Jul 19, 2022
6a76dba
Don't reuse vars
erikjohnston Jul 19, 2022
d4133b2
Add example
erikjohnston Jul 19, 2022
88aa56c
Make `LruCacheget_multi` return something sane.
erikjohnston Jul 19, 2022
f053edb
Woo comments
erikjohnston Jul 20, 2022
740fe2f
Remove use of `cache_key`
erikjohnston Jul 20, 2022
378aec5
More comments
erikjohnston Jul 20, 2022
5709037
Support values being removed from dict
erikjohnston Jul 20, 2022
b376618
Fixup lint
erikjohnston Jul 20, 2022
12e14f2
Make `missing` a list
erikjohnston Jul 20, 2022
fed7755
Don't iterate twice over `dict_key`
erikjohnston Jul 20, 2022
c9f13f3
Clarify comment
erikjohnston Jul 20, 2022
67bb06d
Use iterable rather than generator
erikjohnston Jul 20, 2022
2ec4cab
Add example
erikjohnston Jul 20, 2022
50bb901
Add doc to TreeCache.get
erikjohnston Jul 20, 2022
aa203c6
Note that if full is True known_absent must be empty
erikjohnston Jul 20, 2022
2151474
When fetching full dict don't return partial
erikjohnston Jul 20, 2022
43e0030
Fix test, set takes an iterable
erikjohnston Jul 20, 2022
3c23161
Add simple test for invalidation
erikjohnston Jul 20, 2022
e5ef14d
Fix test now we don't return partial dicts
erikjohnston Jul 21, 2022
10fb0d0
Woo comments
erikjohnston Jul 21, 2022
d521be2
Comment if dict_keys is None
erikjohnston Jul 21, 2022
3c84a98
Document update doesn't invalidate
erikjohnston Jul 21, 2022
9c54881
Update synapse/util/caches/dictionary_cache.py
erikjohnston Jul 21, 2022
daa2741
Flesh out return value
erikjohnston Jul 21, 2022
055a5dd
Lint
erikjohnston Jul 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions synapse/util/caches/dictionary_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ def get(
Args:
key
dict_keys: If given a set of keys then return only those keys
that exist in the cache.
that exist in the cache. If None then returns the full dict
if it is in the cache.

Returns:
DictionaryEntry

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't document what happens if dict_keys is None, but we don't have the full dict cached. Could it, please?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... please?

I think it returns some fixed shape of DictionaryEntry ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I'd put some docs under the dict_keys arg (and there is some in DictionaryEntry), but have also added some in the return value too.

Expand Down Expand Up @@ -251,7 +252,7 @@ def invalidate(self, key: KT) -> None:
# We want to drop all information about the dict for the given key, so
# we use `del_multi` to delete it all in one go.
#
# We ignore the type error here `del_mutli` accepts a truncated key
# We ignore the type error here: `del_multi` accepts a truncated key
# (when the key type is a tuple).
self.cache.del_multi((key,)) # type: ignore[arg-type]

Expand All @@ -267,7 +268,10 @@ def update(
value: Dict[DKT, DV],
fetched_keys: Optional[Iterable[DKT]] = None,
) -> None:
"""Updates the entry in the cache
"""Updates the entry in the cache.

Note: This does *not* invalidate any existing entries for the `key`.
When the underlying data is changed `.invalidate(key)` must be called.
Comment thread
erikjohnston marked this conversation as resolved.
Outdated

Args:
sequence
Expand Down
2 changes: 1 addition & 1 deletion synapse/util/caches/treecache.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get(self, key, default=None):

If `key` is only a partial key (i.e. a truncated tuple) then returns a
`TreeCacheNode`, which can be passed to the `iterate_tree_cache_*`
functions to iterate over all values in the cache with keys that start
functions to iterate over all entries in the cache with keys that start
with the given partial key.
"""

Expand Down
3 changes: 3 additions & 0 deletions tests/util/test_dict_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ def test_invalidation(self):
key = "some_key"

seq = self.cache.sequence
# start by populating a "full dict" entry
self.cache.update(seq, key, {"a": "b", "c": "d"})
Comment thread
erikjohnston marked this conversation as resolved.

# add a bunch of individual entries, also keeping the individual
# entry for "a" warm.
for i in range(20):
Comment thread
erikjohnston marked this conversation as resolved.
self.cache.get(key, ["a"])
self.cache.update(seq, f"key{i}", {1: 2})
Expand Down