Struct opendal::layers::CacheLayer
source · pub struct CacheLayer { /* private fields */ }
Expand description
ContentCacheLayer will add content data cache support for OpenDAL.
Notes
This layer only maintains its own states. Users should care about the cache consistency by themselves. For example, in the following situations, users could get out-dated metadata cache:
- Users have operations on underlying operator directly.
- Other nodes have operations on underlying storage directly.
- Concurrent read/write/delete on the same path.
To make sure content cache consistent across the cluster, please make sure all nodes in the cluster use the same cache services like redis or tikv.
Examples
Use memory as cache.
use std::sync::Arc;
use anyhow::Result;
use opendal::layers::CacheLayer;
use opendal::services::memory;
use opendal::Operator;
use opendal::Scheme;
let _ = Operator::from_env(Scheme::Fs)
.expect("must init")
.layer(CacheLayer::new(
Operator::from_env(Scheme::Memory).expect("must init"),
));
Use memory and fs as a two level cache.
use std::sync::Arc;
use anyhow::Result;
use opendal::layers::CacheLayer;
use opendal::services::memory;
use opendal::Operator;
use opendal::Scheme;
let _ = Operator::from_env(Scheme::Fs)
.expect("must init")
.layer(CacheLayer::new(
Operator::from_env(Scheme::Fs).expect("must init"),
))
.layer(CacheLayer::new(
Operator::from_env(Scheme::Memory).expect("must init"),
));
Implementations§
source§impl CacheLayer
impl CacheLayer
sourcepub fn with_policy(self, policy: impl CachePolicy) -> Self
pub fn with_policy(self, policy: impl CachePolicy) -> Self
Update the cache layer’s logic.
Trait Implementations§
source§impl Clone for CacheLayer
impl Clone for CacheLayer
source§fn clone(&self) -> CacheLayer
fn clone(&self) -> CacheLayer
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more