Get cached RowDescription if available
(&self, key: &RowDescriptionKey)
| 76 | |
| 77 | /// Get cached RowDescription if available |
| 78 | pub fn get(&self, key: &RowDescriptionKey) -> Option<Vec<FieldDescription>> { |
| 79 | let mut cache = self.cache.write().unwrap(); |
| 80 | let mut stats = self.stats.write().unwrap(); |
| 81 | |
| 82 | if let Some(entry) = cache.get_mut(key) { |
| 83 | // Check TTL |
| 84 | if entry.created_at.elapsed() < self.ttl { |
| 85 | entry.hit_count += 1; |
| 86 | stats.hits += 1; |
| 87 | debug!("RowDescription cache hit for query: {}", &key.query[..50.min(key.query.len())]); |
| 88 | return Some(entry.fields.clone()); |
| 89 | } else { |
| 90 | // Entry expired |
| 91 | cache.remove(key); |
| 92 | stats.evictions += 1; |
| 93 | stats.entries = cache.len(); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | stats.misses += 1; |
| 98 | None |
| 99 | } |
| 100 | |
| 101 | /// Insert a new RowDescription into the cache |
| 102 | pub fn insert(&self, key: RowDescriptionKey, fields: Vec<FieldDescription>) { |