Xuanwo commented on code in PR #5906:
URL: https://github.com/apache/opendal/pull/5906#discussion_r2020225713


##########
core/src/layers/cache.rs:
##########
@@ -0,0 +1,187 @@
+use std::sync::Arc;
+
+use crate::raw::*;
+use crate::*;
+use bytes::Bytes;
+use foyer::{DirectFsDeviceOptions, Engine, HybridCache, HybridCacheBuilder};
+use serde::{Deserialize, Serialize};
+
+pub struct CacheLayer {
+    cache: Arc<HybridCache<CacheKey, CacheValue>>,
+}
+
+impl CacheLayer {
+    pub async fn new(
+        disk_cache_dir: &str,
+        disk_capacity_mb: usize,
+        memory_capacity_mb: usize,
+    ) -> Result<Self> {
+        const MB: usize = 1 << 20;
+
+        let cache = HybridCacheBuilder::new()
+            .with_name("opendal")
+            .memory(memory_capacity_mb * MB)
+            .storage(Engine::Large)
+            .with_device_options(
+                
DirectFsDeviceOptions::new(disk_cache_dir).with_capacity(disk_capacity_mb * MB),
+            )
+            .build()
+            .await
+            .map_err(|e| Error::new(ErrorKind::Unexpected, e.to_string()))?;
+
+        Ok(Self {
+            cache: Arc::new(cache),
+        })
+    }
+}
+
+impl<A: Access> Layer<A> for CacheLayer {
+    type LayeredAccess = CacheAccessor<A>;
+
+    fn layer(&self, inner: A) -> Self::LayeredAccess {
+        CacheAccessor {
+            inner,
+            cache: Arc::clone(&self.cache),
+        }
+    }
+}
+
+#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
+struct CacheKey {
+    path: String,
+    args: OpRead,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+struct CacheValue {
+    rp: RpRead,

Review Comment:
   At the current of time, we can always return `RpRead::default()`.



-- 
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: commits-unsubscr...@opendal.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to