(text: &str, doc: &SceneDoc)
| 56 | doc |
| 57 | } |
| 58 | |
| 59 | pub fn store_scene_doc_cache(text: &str, doc: &SceneDoc) { |
| 60 | let cache = ACTIVE_SCENE_DOC_CACHE.get_or_init(|| Mutex::new(Vec::new())); |
| 61 | if let Ok(mut guard) = cache.lock() { |
| 62 | if let Some(idx) = guard.iter().position(|cached| cached.text == text) { |
| 63 | guard.remove(idx); |
| 64 | } |
| 65 | guard.push(CachedSceneDoc::new(text.to_string(), Arc::new(doc.clone()))); |
| 66 | if guard.len() > SCENE_DOC_CACHE_LIMIT { |
| 67 | guard.remove(0); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | impl CachedSceneDoc { |