datafusion_execution/cache/mod.rs
1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18pub mod cache_manager;
19pub mod cache_unit;
20pub mod lru_queue;
21
22/// The cache accessor, users usually working on this interface while manipulating caches.
23/// This interface does not get `mut` references and thus has to handle its own
24/// locking via internal mutability. It can be accessed via multiple concurrent queries
25/// during planning and execution.
26pub trait CacheAccessor<K, V>: Send + Sync {
27 // Extra info but not part of the cache key or cache value.
28 type Extra: Clone;
29
30 /// Get value from cache.
31 fn get(&self, k: &K) -> Option<V>;
32 /// Get value from cache.
33 fn get_with_extra(&self, k: &K, e: &Self::Extra) -> Option<V>;
34 /// Put value into cache. Returns the old value associated with the key if there was one.
35 fn put(&self, key: &K, value: V) -> Option<V>;
36 /// Put value into cache. Returns the old value associated with the key if there was one.
37 fn put_with_extra(&self, key: &K, value: V, e: &Self::Extra) -> Option<V>;
38 /// Remove an entry from the cache, returning value if they existed in the map.
39 fn remove(&mut self, k: &K) -> Option<V>;
40 /// Check if the cache contains a specific key.
41 fn contains_key(&self, k: &K) -> bool;
42 /// Fetch the total number of cache entries.
43 fn len(&self) -> usize;
44 /// Check if the Cache collection is empty or not.
45 fn is_empty(&self) -> bool {
46 self.len() == 0
47 }
48 /// Remove all entries from the cache.
49 fn clear(&self);
50 /// Return the cache name.
51 fn name(&self) -> String;
52}