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;
20
21/// The cache accessor, users usually working on this interface while manipulating caches.
22/// This interface does not get `mut` references and thus has to handle its own
23/// locking via internal mutability. It can be accessed via multiple concurrent queries
24/// during planning and execution.
25pub trait CacheAccessor<K, V>: Send + Sync {
26 // Extra info but not part of the cache key or cache value.
27 type Extra: Clone;
28
29 /// Get value from cache.
30 fn get(&self, k: &K) -> Option<V>;
31 /// Get value from cache.
32 fn get_with_extra(&self, k: &K, e: &Self::Extra) -> Option<V>;
33 /// Put value into cache. Returns the old value associated with the key if there was one.
34 fn put(&self, key: &K, value: V) -> Option<V>;
35 /// Put value into cache. Returns the old value associated with the key if there was one.
36 fn put_with_extra(&self, key: &K, value: V, e: &Self::Extra) -> Option<V>;
37 /// Remove an entry from the cache, returning value if they existed in the map.
38 fn remove(&mut self, k: &K) -> Option<V>;
39 /// Check if the cache contains a specific key.
40 fn contains_key(&self, k: &K) -> bool;
41 /// Fetch the total number of cache entries.
42 fn len(&self) -> usize;
43 /// Check if the Cache collection is empty or not.
44 fn is_empty(&self) -> bool {
45 self.len() == 0
46 }
47 /// Remove all entries from the cache.
48 fn clear(&self);
49 /// Return the cache name.
50 fn name(&self) -> String;
51}