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§

Create a new metadata cache layer.

Update the cache layer’s logic.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Intercept the operations on the underlying storage.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Applies the Compat adapter by value. Read more
Applies the Compat adapter by shared reference. Read more
Applies the Compat adapter by mutable reference. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more