File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed
src/frequenz/channels/experimental Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change 1111stores the latest value received by that receiver for each key separately.
1212
1313The `GroupingLatestValueCache` implements the [`Mapping`][collections.abc.Mapping]
14- interface, so it can be used like a dictionary. In addition, it provides a
15- [has_value][frequenz.channels.experimental.GroupingLatestValueCache.has_value] method to
16- check if a value has been received for a specific key, and a
17- [clear][frequenz.channels.experimental.GroupingLatestValueCache.clear] method to clear
18- the cached value for a specific key .
14+ interface, so it can be used like a dictionary. It is not
15+ a [`MutableMapping`][collections.abc.MutableMapping] because users can't mutate the
16+ cache directly, it is only mutated by the underlying receiver. There is one exception
17+ though, users can clear individual keys from the cache using the
18+ [clear][frequenz.channels.experimental.GroupingLatestValueCache.clear] method .
1919
2020Example:
2121 ```python
2727 cache = GroupingLatestValueCache(channel.new_receiver(), key=lambda x: x[0])
2828 sender = channel.new_sender()
2929
30- assert not cache.has_value(6)
30+ assert cache.get(6) is None
31+ assert 6 not in cache
3132
3233 await sender.send((6, "twenty-six"))
3334
34- assert cache.has_value(6)
35+ assert 6 in cache
3536 assert cache.get(6) == (6, "twenty-six")
37+
38+ await cache.stop()
3639 ```
3740"""
3841
You can’t perform that action at this time.
0 commit comments