pub struct SmartCacheManager {
l1_cache: LRUCache<u64, CachedTranslation>,
l2_cache: FrequencyWeightedCache<u64, CachedTranslation>,
stats: CacheStats,
config: CacheConfig,
predictor: CachePredictor,
}Expand description
智能缓存管理器
Fields§
§l1_cache: LRUCache<u64, CachedTranslation>L1缓存:最近使用的翻译(快速访问)
l2_cache: FrequencyWeightedCache<u64, CachedTranslation>L2缓存:频率权重缓存(中等频率访问)
stats: CacheStats缓存统计
config: CacheConfig配置
predictor: CachePredictor预测器
Implementations§
Source§impl SmartCacheManager
impl SmartCacheManager
Sourcepub async fn new(
translation_config: &TranslationConfig,
) -> TranslationResult<Self>
pub async fn new( translation_config: &TranslationConfig, ) -> TranslationResult<Self>
创建新的智能缓存管理器
Sourcepub async fn set(
&mut self,
text: &str,
translation: String,
) -> TranslationResult<()>
pub async fn set( &mut self, text: &str, translation: String, ) -> TranslationResult<()>
设置翻译到缓存
Sourcepub async fn preload(
&mut self,
translations: Vec<(String, String)>,
) -> TranslationResult<()>
pub async fn preload( &mut self, translations: Vec<(String, String)>, ) -> TranslationResult<()>
批量预热缓存
Sourcepub fn stats(&self) -> &CacheStats
pub fn stats(&self) -> &CacheStats
获取缓存统计
Sourcepub async fn cleanup_expired(&mut self) -> TranslationResult<()>
pub async fn cleanup_expired(&mut self) -> TranslationResult<()>
清理过期缓存
Sourcefn should_cache_in_l1(&self, text: &str) -> bool
fn should_cache_in_l1(&self, text: &str) -> bool
判断是否应该缓存到L1
Sourceasync fn check_memory_usage(&mut self) -> TranslationResult<()>
async fn check_memory_usage(&mut self) -> TranslationResult<()>
检查内存使用
Auto Trait Implementations§
impl !Freeze for SmartCacheManager
impl RefUnwindSafe for SmartCacheManager
impl Send for SmartCacheManager
impl Sync for SmartCacheManager
impl Unpin for SmartCacheManager
impl UnwindSafe for SmartCacheManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more