Skip to main content

hyperlane_plugin_cache/
trait.rs

1use super::*;
2
3/// Pluggable asynchronous response/data cache store (in-memory, Redis, Memcached, etc.).
4pub trait CacheStore: Send + Sync + 'static {
5    /// Looks up an unexpired [`CachedValue`] for `key`.
6    ///
7    /// # Arguments
8    ///
9    /// - `&'a self` - Shared reference to self.
10    /// - `&'a str` - Cache key.
11    ///
12    /// # Returns
13    ///
14    /// - `CacheFuture<'a, Option<CachedValue>>` - Cached value when present and unexpired.
15    fn get<'a>(&'a self, key: &'a str) -> CacheFuture<'a, Option<CachedValue>>;
16
17    /// Inserts or replaces `value` under `key` with time-to-live `ttl_ms`.
18    ///
19    /// # Arguments
20    ///
21    /// - `String` - Cache key.
22    /// - `CachedValue` - Payload and metadata to cache.
23    /// - `u64` - Entry TTL in milliseconds.
24    ///
25    /// # Returns
26    ///
27    /// - `CacheFuture<'_, ()>` - Completion future.
28    fn put(&self, key: String, value: CachedValue, ttl_ms: u64) -> CacheFuture<'_, ()>;
29
30    /// Removes a single key from the cache.
31    ///
32    /// # Arguments
33    ///
34    /// - `&'a self` - Shared reference to self.
35    /// - `&'a str` - Cache key to invalidate.
36    ///
37    /// # Returns
38    ///
39    /// - `CacheFuture<'a, bool>` - `true` when an entry was removed.
40    fn remove<'a>(&'a self, key: &'a str) -> CacheFuture<'a, bool>;
41
42    /// Evicts expired entries and returns the count removed.
43    ///
44    /// # Returns
45    ///
46    /// - `usize` - Number of expired entries reclaimed.
47    fn purge_expired(&self) -> usize {
48        0
49    }
50}