refactor: 抽离 AI pipeline 与调度共享能力逻辑

This commit is contained in:
fawney19
2026-04-10 01:46:14 +08:00
parent b901a6ffc7
commit 5014e2f5fd
255 changed files with 15057 additions and 3115 deletions

View File

@@ -2,4 +2,4 @@ mod namespace;
mod ttl_map;
pub use namespace::CacheKeyNamespace;
pub use ttl_map::ExpiringMap;
pub use ttl_map::{ExpiringMap, ExpiringMapFreshEntry};

View File

@@ -14,6 +14,13 @@ pub struct ExpiringMap<K, V> {
entries: Mutex<HashMap<K, TimedEntry<V>>>,
}
#[derive(Debug, Clone)]
pub struct ExpiringMapFreshEntry<K, V> {
pub key: K,
pub value: V,
pub age: Duration,
}
impl<K, V> Default for ExpiringMap<K, V> {
fn default() -> Self {
Self {
@@ -98,6 +105,22 @@ where
pub fn contains_fresh(&self, key: &K, ttl: Duration) -> bool {
self.get_fresh(key, ttl).is_some()
}
pub fn snapshot_fresh(&self, ttl: Duration) -> Vec<ExpiringMapFreshEntry<K, V>> {
let Ok(mut entries) = self.entries.lock() else {
return Vec::new();
};
prune_expired(&mut entries, ttl);
entries
.iter()
.map(|(key, entry)| ExpiringMapFreshEntry {
key: key.clone(),
value: entry.value.clone(),
age: entry.inserted_at.elapsed(),
})
.collect()
}
}
fn prune_expired<K, V>(entries: &mut HashMap<K, TimedEntry<V>>, ttl: Duration)