Skip to main content

Moka

Moka services support.

Capabilities

This service can be used to:

  • stat
  • read
  • write
  • create_dir
  • delete
  • copy
  • rename
  • list
  • scan
  • presign
  • blocking

Configuration

  • name: Set the name for this cache instance.
  • 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

Example

Via Builder

use anyhow::Result;
use opendal::services::Moka;
use opendal::Operator;

#[tokio::main]
async fn main() -> Result<()> {
let mut builder = Moka::default();
builder.name("opendal");

let op: Operator = Operator::new(builder)?.finish();
Ok(())
}

Via Config

use anyhow::Result;
use opendal::Operator;
use opendal::Scheme;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<()> {
let mut map = HashMap::new();
map.insert("name".to_string(), "your_cache_name".to_string());

let op: Operator = Operator::via_map(Scheme::Moka, map)?;
Ok(())
}