File tree Expand file tree Collapse file tree 2 files changed +38
-3
lines changed
docs/user-guide/receiving Expand file tree Collapse file tree 2 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 1+ # Caching
2+
3+ ::: frequenz.channels._ latest_value_cache
4+ options:
5+ inherited_members: [ ]
6+ members: [ ]
7+ show_bases: false
8+ show_root_heading: false
9+ show_root_toc_entry: false
10+ show_source: false
Original file line number Diff line number Diff line change 11# License: MIT
22# Copyright © 2024 Frequenz Energy-as-a-Service GmbH
33
4- """A cache that stores the latest value in a receiver.
4+ """The LatestValueCache caches the latest value in a receiver.
55
6- It provides a way to look up the latest value in a stream without any delay,
7- as long as there has been one value received.
6+ It provides a way to look up the latest value in a stream whenever required, as
7+ long as there has been one value received.
8+
9+ [LatestValueCache][frequenz.channels.LatestValueCache] takes a
10+ [Receiver][frequenz.channels.Receiver] as an argument and stores the latest
11+ value received by that receiver. As soon as a value is received, its
12+ [`has_value`][frequenz.channels.LatestValueCache.has_value] method returns
13+ `True`, and its [`get`][frequenz.channels.LatestValueCache.get] method returns
14+ the latest value received. The `get` method will raise an exception if called
15+ before any messages have been received from the receiver.
16+
17+ Example:
18+ ```python
19+ from frequenz.channels import Broadcast, LatestValueCache
20+
21+ channel = Broadcast[int](name="lvc_test")
22+
23+ cache = LatestValueCache(channel.new_receiver())
24+ sender = channel.new_sender()
25+
26+ assert not cache.has_value()
27+
28+ await sender.send(5)
29+
30+ assert cache.has_value()
31+ assert cache.get() == 5
32+ ```
833"""
934
1035import asyncio
You can’t perform that action at this time.
0 commit comments