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
22mod file_metadata_cache;
23mod list_files_cache;
24
25pub use file_metadata_cache::DefaultFilesMetadataCache;
26pub use list_files_cache::DefaultListFilesCache;
27pub use list_files_cache::TableScopedPath;
28
29/// A trait that can be implemented to provide custom cache behavior for the caches managed by
30/// [`cache_manager::CacheManager`].
31///
32/// Implementations must handle their own locking via internal mutability, as methods do not
33/// take mutable references and may be accessed by multiple concurrent queries.
34pub trait CacheAccessor<K, V>: Send + Sync {
35 // Extra info but not part of the cache key or cache value.
36 type Extra: Clone;
37
38 /// Get value from cache.
39 fn get(&self, k: &K) -> Option<V>;
40 /// Get value from cache.
41 fn get_with_extra(&self, k: &K, e: &Self::Extra) -> Option<V>;
42 /// Put value into cache. Returns the old value associated with the key if there was one.
43 fn put(&self, key: &K, value: V) -> Option<V>;
44 /// Put value into cache. Returns the old value associated with the key if there was one.
45 fn put_with_extra(&self, key: &K, value: V, e: &Self::Extra) -> Option<V>;
46 /// Remove an entry from the cache, returning value if they existed in the map.
47 fn remove(&self, k: &K) -> Option<V>;
48 /// Check if the cache contains a specific key.
49 fn contains_key(&self, k: &K) -> bool;
50 /// Fetch the total number of cache entries.
51 fn len(&self) -> usize;
52 /// Check if the Cache collection is empty or not.
53 fn is_empty(&self) -> bool {
54 self.len() == 0
55 }
56 /// Remove all entries from the cache.
57 fn clear(&self);
58 /// Return the cache name.
59 fn name(&self) -> String;
60}