Expand description
This file contains an interface to a static DashMap, such that the stored values can be extracted with static lifetimes, and without a Ref Guard.
The underlying implementation stores all values within an Arc. When a value is requested, the interior Arc’s address is returned directly. This is safe, as:
- The static DashMap holds a strong reference to the Arc, so its lifetime is static. There is no risk of a reference becoming invalid.
- Because the DashMap stores an Arc, the interior address of the value is outside the realm of the Map. Therefore, insertions and deletions will not alter the value within the Arc, even if it modifies the address of the Arc itself.cache
- Typical Rust thread-safety and reference rules still apply. You can take as many immutable references as you want, but only a single mutable reference. This means, if you need to query the data across multiple threads, you’ll need to wrap the data in a Mutex or similar interior-mutable structure.
To use this, you will need to define two static values:
- The DashMap itself. Define a new static cache::CacheStatic with the Key and Value types needed.
- Instantiate a static of the cache::Cache object within a LazyLock, with its value taking a reference to the above DashMap.
Then, you can use the Cache to retrieve static values, and insert them.
Structs§
- Cache
- The Cache interface. Store within a LazyLock, and pass the corresponding CacheStatic to the LazyLock::new()
Type Aliases§
- Cache
Static - The underlying data store. You should not use this besides passing it to the Cache instance.