Expand description
The Pantry
is useful for temporarily storing for later use values that
might “decay” (become unusable) over time.
Create a Pantry
value and use its store
function to store values
for later use. A key is provided along with the value, so that the value
can be retrieved later using the same key. A worker thread is spawned
which monitors the values and automatically drops any which have “decayed”.
Values must implement the Perishable
trait, whose perished
function
asynchronously completes once the value has decayed.
Use the fetch
asynchronous function on the Pantry
with a key to
retrieve a value previously stored using that key. A value is only
returned if it was stored using the same key and has not decayed since it
was stored.
Multiple values may have the same key, with the caveat that the values stored under a given key may not be returned in the same order in which they were stored.
Structs§
- Pantry
- Each value of this type maintains a collection of stored values that might
“decay” or become unusable over time. Values are added to the collection
by calling
store
and providing the value along with a key that can be used to retrieve the value later. Values added to the collection are monitored by a worker thread and dropped if the futures returned by theirperished
functions complete.
Traits§
- Perishable
- This is the trait that values must implement in order to be stored in the
Pantry
. Note that since the trait has an asynchronous method, currently theasync_trait
attribute from theasync-trait
crate must be added to implementations.