You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by ko...@apache.org on 2025/06/08 13:35:34 UTC

(opendal) branch change-moka-cache-type created (now c00e0af32)

This is an automated email from the ASF dual-hosted git repository.

koushiro pushed a change to branch change-moka-cache-type
in repository https://gitbox.apache.org/repos/asf/opendal.git


      at c00e0af32 refactor(services/moka): change sync::Cache to future::Cache

This branch includes the following new commits:

     new c00e0af32 refactor(services/moka): change sync::Cache to future::Cache

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(opendal) 01/01: refactor(services/moka): change sync::Cache to future::Cache

Posted by ko...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

koushiro pushed a commit to branch change-moka-cache-type
in repository https://gitbox.apache.org/repos/asf/opendal.git

commit c00e0af327effeaf5658c81e2fa536f6e772da63
Author: koushiro <ko...@gmail.com>
AuthorDate: Sun Jun 8 21:35:21 2025 +0800

    refactor(services/moka): change sync::Cache to future::Cache
---
 core/src/services/moka/backend.rs | 28 ++++++++--------------------
 core/src/services/moka/config.rs  | 11 +++--------
 core/src/services/moka/docs.md    |  1 -
 3 files changed, 11 insertions(+), 29 deletions(-)

diff --git a/core/src/services/moka/backend.rs b/core/src/services/moka/backend.rs
index ed2da79cd..c1354e6be 100644
--- a/core/src/services/moka/backend.rs
+++ b/core/src/services/moka/backend.rs
@@ -20,8 +20,8 @@ use std::fmt::Formatter;
 use std::time::Duration;
 
 use log::debug;
-use moka::sync::CacheBuilder;
-use moka::sync::SegmentedCache;
+use moka::future::Cache;
+use moka::future::CacheBuilder;
 
 use crate::raw::adapters::typed_kv;
 use crate::raw::*;
@@ -81,15 +81,6 @@ impl MokaBuilder {
         self
     }
 
-    /// Sets the segments number of the cache.
-    ///
-    /// Refer to [`moka::sync::CacheBuilder::segments`](https://docs.rs/moka/latest/moka/sync/struct.CacheBuilder.html#method.segments)
-    pub fn segments(mut self, v: usize) -> Self {
-        assert!(v != 0);
-        self.config.num_segments = Some(v);
-        self
-    }
-
     /// Set root path of this backend
     pub fn root(mut self, path: &str) -> Self {
         self.config.root = if path.is_empty() {
@@ -97,7 +88,6 @@ impl MokaBuilder {
         } else {
             Some(path.to_string())
         };
-
         self
     }
 }
@@ -109,8 +99,8 @@ impl Builder for MokaBuilder {
     fn build(self) -> Result<impl Access> {
         debug!("backend build started: {:?}", &self);
 
-        let mut builder: CacheBuilder<String, typed_kv::Value, _> =
-            SegmentedCache::builder(self.config.num_segments.unwrap_or(1));
+        let mut builder: CacheBuilder<String, typed_kv::Value, _> = Cache::builder();
+
         // Use entries' bytes as capacity weigher.
         builder = builder.weigher(|k, v| (k.len() + v.size()) as u32);
         if let Some(v) = &self.config.name {
@@ -144,7 +134,7 @@ pub type MokaBackend = typed_kv::Backend<Adapter>;
 
 #[derive(Clone)]
 pub struct Adapter {
-    inner: SegmentedCache<String, typed_kv::Value>,
+    inner: Cache<String, typed_kv::Value>,
 }
 
 impl Debug for Adapter {
@@ -172,21 +162,19 @@ impl typed_kv::Adapter for Adapter {
     }
 
     async fn get(&self, path: &str) -> Result<Option<typed_kv::Value>> {
-        match self.inner.get(path) {
+        match self.inner.get(path).await {
             None => Ok(None),
             Some(bs) => Ok(Some(bs)),
         }
     }
 
     async fn set(&self, path: &str, value: typed_kv::Value) -> Result<()> {
-        self.inner.insert(path.to_string(), value);
-
+        self.inner.insert(path.to_string(), value).await;
         Ok(())
     }
 
     async fn delete(&self, path: &str) -> Result<()> {
-        self.inner.invalidate(path);
-
+        self.inner.invalidate(path).await;
         Ok(())
     }
 
diff --git a/core/src/services/moka/config.rs b/core/src/services/moka/config.rs
index 55458674b..69641d482 100644
--- a/core/src/services/moka/config.rs
+++ b/core/src/services/moka/config.rs
@@ -31,20 +31,16 @@ pub struct MokaConfig {
     pub name: Option<String>,
     /// Sets the max capacity of the cache.
     ///
-    /// Refer to [`moka::sync::CacheBuilder::max_capacity`](https://docs.rs/moka/latest/moka/sync/struct.CacheBuilder.html#method.max_capacity)
+    /// Refer to [`moka::future::CacheBuilder::max_capacity`](https://docs.rs/moka/latest/moka/future/struct.CacheBuilder.html#method.max_capacity)
     pub max_capacity: Option<u64>,
     /// Sets the time to live of the cache.
     ///
-    /// Refer to [`moka::sync::CacheBuilder::time_to_live`](https://docs.rs/moka/latest/moka/sync/struct.CacheBuilder.html#method.time_to_live)
+    /// Refer to [`moka::future::CacheBuilder::time_to_live`](https://docs.rs/moka/latest/moka/future/struct.CacheBuilder.html#method.time_to_live)
     pub time_to_live: Option<Duration>,
     /// Sets the time to idle of the cache.
     ///
-    /// Refer to [`moka::sync::CacheBuilder::time_to_idle`](https://docs.rs/moka/latest/moka/sync/struct.CacheBuilder.html#method.time_to_idle)
+    /// Refer to [`moka::future::CacheBuilder::time_to_idle`](https://docs.rs/moka/latest/moka/future/struct.CacheBuilder.html#method.time_to_idle)
     pub time_to_idle: Option<Duration>,
-    /// Sets the segments number of the cache.
-    ///
-    /// Refer to [`moka::sync::CacheBuilder::segments`](https://docs.rs/moka/latest/moka/sync/struct.CacheBuilder.html#method.segments)
-    pub num_segments: Option<usize>,
 
     /// root path of this backend
     pub root: Option<String>,
@@ -57,7 +53,6 @@ impl Debug for MokaConfig {
             .field("max_capacity", &self.max_capacity)
             .field("time_to_live", &self.time_to_live)
             .field("time_to_idle", &self.time_to_idle)
-            .field("num_segments", &self.num_segments)
             .field("root", &self.root)
             .finish_non_exhaustive()
     }
diff --git a/core/src/services/moka/docs.md b/core/src/services/moka/docs.md
index 8f23d915b..b544933bf 100644
--- a/core/src/services/moka/docs.md
+++ b/core/src/services/moka/docs.md
@@ -19,7 +19,6 @@ This service can be used to:
 - `max_capacity`: Set the max capacity of the cache.
 - `time_to_live`: Set the time to live of the cache.
 - `time_to_idle`: Set the time to idle of the cache.
-- `num_segments`: Set the segments number of the cache.
 
 You can refer to [`MokaBuilder`]'s docs for more information