mkleen commented on code in PR #22613:
URL: https://github.com/apache/datafusion/pull/22613#discussion_r3329859790


##########
datafusion/execution/src/cache/mod.rs:
##########
@@ -78,3 +82,83 @@ pub trait CacheAccessor<K, V>: Send + Sync {
     /// Return the cache name.
     fn name(&self) -> String;
 }
+
+/// A managed cache with capacity, expiration, and introspection policies.
+///
+/// Keys must implement [`Key`] and values must implement [`Value`] so
+/// the implementation can account for heap usage when enforcing the cache 
limit.
+///
+pub trait Cache<K: Key, V: Value>: CacheAccessor<K, V> {
+    /// Current memory budget, in bytes.
+    fn cache_limit(&self) -> usize;
+
+    /// Change the memory budget in bytes.
+    fn update_cache_limit(&self, limit: usize);
+
+    /// Time-to-live applied to newly inserted entries, or `None` if entries
+    /// never expire on their own.
+    fn cache_ttl(&self) -> Option<Duration>;
+
+    /// Change the TTL applied to subsequent inserts.
+    fn update_cache_ttl(&self, _ttl: Option<Duration>);
+
+    /// Invalidate every entry associated with `table_ref`.
+    fn drop_table_entries(
+        &self,
+        _table_ref: &Option<TableReference>,
+    ) -> datafusion_common::Result<()>;
+
+    /// Snapshot of all current entries with per-entry metadata (size, hits,
+    /// expiration) for diagnostics and observability.
+    fn list_entries(&self) -> HashMap<K, CacheEntryInfo<V>>;
+}
+
+/// Key type for entries stored in a [`Cache`].
+pub trait Key: Clone + Eq + Hash + Send + Sync + Debug {
+    /// Size of the key in bytes, used for cache memory accounting.
+    fn size(&self) -> usize;
+
+    /// Table this key is associated with, or `None` if the key is not
+    /// table-scoped.
+    fn table_ref(&self) -> Option<&TableReference>;
+}
+
+/// Value type for entries stored in a [`Cache`].
+pub trait Value: Clone + Send + Sync {

Review Comment:
   OK.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to