use std::fmt::Debug;
use dashmap::DashMap;
use opendal_core::*;
#[derive(Clone)]
pub struct DashmapValue {
pub metadata: Metadata,
pub content: Buffer,
}
#[derive(Clone)]
pub struct DashmapCore {
pub cache: DashMap<String, DashmapValue>,
}
impl Debug for DashmapCore {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DashmapCore")
.field("size", &self.cache.len())
.finish()
}
}
impl DashmapCore {
pub fn get(&self, key: &str) -> Result<Option<DashmapValue>> {
Ok(self.cache.get(key).map(|v| v.value().clone()))
}
pub fn set(&self, key: &str, value: DashmapValue) -> Result<()> {
self.cache.insert(key.to_string(), value);
Ok(())
}
pub fn delete(&self, key: &str) -> Result<()> {
self.cache.remove(key);
Ok(())
}
}