pub trait CacheableService: Service {
type CacheKey: Send + Sync + Hash + Eq + Clone;
type CacheValue: Send + Sync + Clone;
// Required methods
fn get_from_cache(&self, key: &Self::CacheKey) -> Option<Self::CacheValue>;
fn put_to_cache(&self, key: Self::CacheKey, value: Self::CacheValue);
fn clear_cache(&self);
// Provided method
fn cache_ttl(&self) -> u64 { ... }
}Expand description
带缓存的服务 trait
为服务提供缓存机制支持
Required Associated Types§
Sourcetype CacheValue: Send + Sync + Clone
type CacheValue: Send + Sync + Clone
缓存值类型
Required Methods§
Sourcefn get_from_cache(&self, key: &Self::CacheKey) -> Option<Self::CacheValue>
fn get_from_cache(&self, key: &Self::CacheKey) -> Option<Self::CacheValue>
从缓存获取数据
Sourcefn put_to_cache(&self, key: Self::CacheKey, value: Self::CacheValue)
fn put_to_cache(&self, key: Self::CacheKey, value: Self::CacheValue)
将数据存入缓存
Sourcefn clear_cache(&self)
fn clear_cache(&self)
清除缓存