(&self, name: &str)
| 103 | } |
| 104 | |
| 105 | pub fn load_collection(&self, name: &str) -> Result<Arc<CollectionCacheEntry>, WaCustomError> { |
| 106 | // Get or create key for this collection name |
| 107 | let key = self.get_or_create_key(name); |
| 108 | |
| 109 | // Try to get from cache first - this will update LRU tracking |
| 110 | if let Some(entry) = self.cache.get(&key) { |
| 111 | info!("Collection '{}' found in cache", name); |
| 112 | return Ok(entry); |
| 113 | } |
| 114 | |
| 115 | // If not in cache, load it |
| 116 | info!("Loading collection '{}' into cache", name); |
| 117 | let collection_path = self.collections_path.join(name); |
| 118 | if !collection_path.exists() { |
| 119 | return Err(WaCustomError::NotFound(format!( |
| 120 | "Collection '{}' not found", |
| 121 | name |
| 122 | ))); |
| 123 | } |
| 124 | |
| 125 | // Load dense and inverted indexes |
| 126 | let dense_index = self.load_dense_index(name)?; |
| 127 | let inverted_index = self.load_inverted_index(name)?; |
| 128 | |
| 129 | // Create cache entry |
| 130 | let entry = Arc::new(CollectionCacheEntry { |
| 131 | name: name.to_string(), |
| 132 | dense_index, |
| 133 | inverted_index, |
| 134 | last_accessed: Instant::now(), |
| 135 | }); |
| 136 | |
| 137 | // Add to cache - this may trigger eviction if at capacity |
| 138 | self.cache.insert(key, entry.clone()); |
| 139 | info!( |
| 140 | "Added collection '{}' to cache. Current loaded collections count: {}", |
| 141 | name, |
| 142 | self.name_to_key.len() |
| 143 | ); |
| 144 | |
| 145 | Ok(entry) |
| 146 | } |
| 147 | |
| 148 | pub fn unload_collection(&self, name: &str) -> Result<(), WaCustomError> { |
| 149 | // Clean up mappings |
no test coverage detected