pub struct GlobalCache;
cache
only.Expand description
Global cache built on the top of LruCache
.
Implementations§
Source§impl GlobalCache
impl GlobalCache
Sourcepub fn put(
key: impl Into<String>,
value: impl Into<JsonValue>,
) -> Option<JsonValue>
pub fn put( key: impl Into<String>, value: impl Into<JsonValue>, ) -> Option<JsonValue>
Puts a key-value pair into the global cache.
If the key already exists in the cache, then it updates the key’s value and
returns the old value. Otherwise, None
is returned.
Sourcepub fn push(
key: impl Into<String>,
value: impl Into<JsonValue>,
) -> Option<(String, JsonValue)>
pub fn push( key: impl Into<String>, value: impl Into<JsonValue>, ) -> Option<(String, JsonValue)>
Pushes a key-value pair into the global cache. If an entry with the key already
exists in the cache or another cache entry is removed (due to the LRU’s capacity),
then it returns the old entry’s key-value pair. Otherwise, returns None
.
Sourcepub fn get(key: &str) -> Option<JsonValue>
pub fn get(key: &str) -> Option<JsonValue>
Returns a cloned value of the key in the global cache or None
if it is not present in the cache. Moves the key to the head of the LRU list if it exists.
Sourcepub fn peek(key: &str) -> Option<JsonValue>
pub fn peek(key: &str) -> Option<JsonValue>
Returns a cloned value of the key in the global cache or None
if it is not present in the cache. It does not update the LRU list
so the key’s position will be unchanged.
Sourcepub fn contains(key: &str) -> bool
pub fn contains(key: &str) -> bool
Returns a bool indicating whether the given key is in the global cache. Does not update the LRU list.
Sourcepub fn pop(key: &str) -> Option<JsonValue>
pub fn pop(key: &str) -> Option<JsonValue>
Removes and returns the value corresponding to the key from the global cache or
None
if it does not exist.
Sourcepub fn pop_entry(key: &str) -> Option<(String, JsonValue)>
pub fn pop_entry(key: &str) -> Option<(String, JsonValue)>
Removes and returns the key-value pair from the global cache or
None
if it does not exist.
Sourcepub fn pop_lru() -> Option<(String, JsonValue)>
pub fn pop_lru() -> Option<(String, JsonValue)>
Removes and returns the key-value pair corresponding to the least recently used item
or None
if the global cache is empty.
Sourcepub fn len() -> usize
pub fn len() -> usize
Returns the number of key-value pairs that are currently in the global cache.
Sourcepub fn cap() -> NonZeroUsize
pub fn cap() -> NonZeroUsize
Returns the maximum number of key-value pairs the global cache can hold.
Sourcepub fn resize(cap: NonZeroUsize)
pub fn resize(cap: NonZeroUsize)
Resizes the global cache. If the new capacity is smaller than the size of the current cache any entries past the new capacity are discarded.
Trait Implementations§
Source§impl Clone for GlobalCache
impl Clone for GlobalCache
Source§fn clone(&self) -> GlobalCache
fn clone(&self) -> GlobalCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more