pub trait CacheStorage: Send + Sync + 'static {
    type Key: Send + Sync + Clone + Eq + Hash + 'static;
    type Value: Send + Sync + Clone + 'static;

    // Required methods
    fn get(&mut self, key: &Self::Key) -> Option<&Self::Value>;
    fn insert(&mut self, key: Cow<'_, Self::Key>, val: Cow<'_, Self::Value>);
    fn remove(&mut self, key: &Self::Key);
    fn clear(&mut self);
    fn iter(&self) -> Box<dyn Iterator<Item = (&Self::Key, &Self::Value)> + '_>;
}
Available on crate feature dataloader only.
Expand description

Cache storage for DataLoader.

Required Associated Types§

source

type Key: Send + Sync + Clone + Eq + Hash + 'static

The key type of the record.

source

type Value: Send + Sync + Clone + 'static

The value type of the record.

Required Methods§

source

fn get(&mut self, key: &Self::Key) -> Option<&Self::Value>

Returns a reference to the value of the key in the cache or None if it is not present in the cache.

source

fn insert(&mut self, key: Cow<'_, Self::Key>, val: Cow<'_, Self::Value>)

Puts a key-value pair into the cache. If the key already exists in the cache, then it updates the key’s value.

source

fn remove(&mut self, key: &Self::Key)

Removes the value corresponding to the key from the cache.

source

fn clear(&mut self)

Clears the cache, removing all key-value pairs.

source

fn iter(&self) -> Box<dyn Iterator<Item = (&Self::Key, &Self::Value)> + '_>

Returns an iterator over the key-value pairs in the cache.

Implementors§