Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(services/moka, services/mini-moka): Add scan support #2850

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 15 additions & 21 deletions core/src/services/mini_moka/backend.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -167,6 +147,7 @@ impl typed_kv::Adapter for Adapter {
get: true,
set: true,
delete: true,
scan: true,
..Default::default()
},
)
Expand Down Expand Up @@ -202,4 +183,17 @@ impl typed_kv::Adapter for Adapter {

Ok(())
}

async fn scan(&self, path: &str) -> Result<Vec<String>> {
self.blocking_scan(path)
}

fn blocking_scan(&self, path: &str) -> Result<Vec<String>> {
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())
}
}
}
20 changes: 20 additions & 0 deletions 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)
31 changes: 15 additions & 16 deletions core/src/services/moka/backend.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -208,6 +193,7 @@ impl typed_kv::Adapter for Adapter {
get: true,
set: true,
delete: true,
scan: true,
..Default::default()
},
)
Expand Down Expand Up @@ -243,4 +229,17 @@ impl typed_kv::Adapter for Adapter {

Ok(())
}

async fn scan(&self, path: &str) -> Result<Vec<String>> {
self.blocking_scan(path)
}

fn blocking_scan(&self, path: &str) -> Result<Vec<String>> {
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())
}
}
}
15 changes: 15 additions & 0 deletions 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