MCPcopy Create free account
hub / github.com/apache/datafusion / put

Method put

datafusion/execution/src/cache/list_files_cache.rs:242–267  ·  view source on GitHub ↗

Adds a new key-value pair to cache expiring at `now` + the TTL. This means that LRU entries might be evicted if required. If the key is already in the cache, the previous entry is returned. If the size of the entry is greater than the `memory_limit`, the value is not inserted.

(
        &mut self,
        key: &TableScopedPath,
        value: CachedFileList,
        now: Instant,
    )

Source from the content-addressed store, hash-verified

240 /// If the key is already in the cache, the previous entry is returned.
241 /// If the size of the entry is greater than the `memory_limit`, the value is not inserted.
242 fn put(
243 &mut self,
244 key: &TableScopedPath,
245 value: CachedFileList,
246 now: Instant,
247 ) -> Option<CachedFileList> {
248 let entry = ListFilesEntry::try_new(value, self.ttl, now)?;
249 let entry_size = entry.size_bytes;
250
251 // no point in trying to add this value to the cache if it cannot fit entirely
252 if entry_size > self.memory_limit {
253 return None;
254 }
255
256 // if the key is already in the cache, the old value is removed
257 let old_value = self.lru_queue.put(key.clone(), entry);
258 self.memory_used += entry_size;
259
260 if let Some(entry) = &old_value {
261 self.memory_used -= entry.size_bytes;
262 }
263
264 self.evict_entries();
265
266 old_value.map(|v| v.metas)
267 }
268
269 /// Evicts entries from the LRU cache until `memory_used` is lower than `memory_limit`.
270 fn evict_entries(&mut self) {

Callers 15

test_basic_operationsFunction · 0.45
test_lru_eviction_basicFunction · 0.45
test_reject_too_largeFunction · 0.45
test_multiple_evictionsFunction · 0.45
test_cache_limit_resizeFunction · 0.45
test_cache_with_ttlFunction · 0.45
test_memory_trackingFunction · 0.45
test_prefix_filteringFunction · 0.45

Calls 4

nowMethod · 0.80
cloneMethod · 0.45
evict_entriesMethod · 0.45
mapMethod · 0.45

Tested by 15

test_basic_operationsFunction · 0.36
test_lru_eviction_basicFunction · 0.36
test_reject_too_largeFunction · 0.36
test_multiple_evictionsFunction · 0.36
test_cache_limit_resizeFunction · 0.36
test_cache_with_ttlFunction · 0.36
test_memory_trackingFunction · 0.36
test_prefix_filteringFunction · 0.36