use std::time::SystemTime; use std::sync::{Arc, Mutex}; use crate::videos::Video_Item; #[derive(Clone)] pub struct VideoCache{ cache: Arc)>>>, // url -> time+Items } impl VideoCache { pub fn new() -> Self { VideoCache { cache: Arc::new(Mutex::new(std::collections::HashMap::new())), } } pub fn get(&self, key: &str) -> Option<(SystemTime, Vec)> { let cache = self.cache.lock().ok()?; cache.get(key).cloned() } pub fn insert(&self, key: String, value: Vec) { if let Ok(mut cache) = self.cache.lock() { cache.insert(key.clone(), (SystemTime::now(), value.clone())); } } pub fn remove(&self, key: &str) { if let Ok(mut cache) = self.cache.lock() { cache.remove(key); } } }