diff --git a/core/src/services/mini_moka/backend.rs b/core/src/services/mini_moka/backend.rs index 942fe909f5ea..0703fd4de960 100644 --- a/core/src/services/mini_moka/backend.rs +++ b/core/src/services/mini_moka/backend.rs @@ -28,27 +28,7 @@ use crate::raw::adapters::typed_kv; use crate::*; /// [mini-moka](https://github.com/moka-rs/mini-moka) backend support. -/// -/// # Capabilities -/// -/// This service can be used to: -/// -/// - [x] stat -/// - [x] read -/// - [x] write -/// - [x] create_dir -/// - [x] delete -/// - [ ] copy -/// - [ ] rename -/// - [ ] list -/// - [ ] ~~scan~~ -/// - [ ] presign -/// - [ ] blocking -/// -/// # Notes -/// -/// To better assist you in choosing the right cache for your use case, -/// Here's a comparison table with [moka](https://github.com/moka-rs/moka#choosing-the-right-cache-for-your-use-case) +#[doc = include_str!("docs.md")] #[derive(Default, Debug)] pub struct MiniMokaBuilder { /// Sets the max capacity of the cache. @@ -167,6 +147,7 @@ impl typed_kv::Adapter for Adapter { get: true, set: true, delete: true, + scan: true, ..Default::default() }, ) @@ -202,4 +183,17 @@ impl typed_kv::Adapter for Adapter { Ok(()) } + + async fn scan(&self, path: &str) -> Result> { + self.blocking_scan(path) + } + + fn blocking_scan(&self, path: &str) -> Result> { + let keys = self.inner.iter().map(|kv| kv.key().to_string()); + if path.is_empty() { + Ok(keys.collect()) + } else { + Ok(keys.filter(|k| k.starts_with(path)).collect()) + } + } } diff --git a/core/src/services/mini_moka/docs.md b/core/src/services/mini_moka/docs.md new file mode 100644 index 000000000000..3a4f757209d5 --- /dev/null +++ b/core/src/services/mini_moka/docs.md @@ -0,0 +1,20 @@ +## Capabilities + +This service can be used to: + +- [x] stat +- [x] read +- [x] write +- [x] create_dir +- [x] delete +- [ ] copy +- [ ] rename +- [ ] list +- [x] scan +- [ ] presign +- [ ] blocking + +## Notes + +To better assist you in choosing the right cache for your use case, +Here's a comparison table with [moka](https://github.com/moka-rs/moka#choosing-the-right-cache-for-your-use-case) diff --git a/core/src/services/moka/backend.rs b/core/src/services/moka/backend.rs index f6b2a8fc37b9..4b90816305a1 100644 --- a/core/src/services/moka/backend.rs +++ b/core/src/services/moka/backend.rs @@ -28,22 +28,7 @@ use crate::raw::adapters::typed_kv; use crate::*; /// [moka](https://github.com/moka-rs/moka) backend support. -/// -/// # Capabilities -/// -/// This service can be used to: -/// -/// - [x] stat -/// - [x] read -/// - [x] write -/// - [x] create_dir -/// - [x] delete -/// - [ ] copy -/// - [ ] rename -/// - [ ] list -/// - [ ] ~~scan~~ -/// - [ ] presign -/// - [ ] blocking +#[doc = include_str!("docs.md")] #[derive(Default, Debug)] pub struct MokaBuilder { /// Name for this cache instance. @@ -208,6 +193,7 @@ impl typed_kv::Adapter for Adapter { get: true, set: true, delete: true, + scan: true, ..Default::default() }, ) @@ -243,4 +229,17 @@ impl typed_kv::Adapter for Adapter { Ok(()) } + + async fn scan(&self, path: &str) -> Result> { + self.blocking_scan(path) + } + + fn blocking_scan(&self, path: &str) -> Result> { + let keys = self.inner.iter().map(|kv| kv.0.to_string()); + if path.is_empty() { + Ok(keys.collect()) + } else { + Ok(keys.filter(|k| k.starts_with(path)).collect()) + } + } } diff --git a/core/src/services/moka/docs.md b/core/src/services/moka/docs.md new file mode 100644 index 000000000000..89546b9c9f51 --- /dev/null +++ b/core/src/services/moka/docs.md @@ -0,0 +1,15 @@ +## Capabilities + +This service can be used to: + +- [x] stat +- [x] read +- [x] write +- [x] create_dir +- [x] delete +- [ ] copy +- [ ] rename +- [ ] list +- [x] scan +- [ ] presign +- [ ] blocking