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