Struct forceps::Cache[][src]

pub struct Cache { /* fields omitted */ }

The main component of forceps, acts as the API for interacting with the on-disk API.

This structure exposes read, write, and misc metadata operations. read and write are both async, whereas all metadata operations are sync. To create this structure, use the CacheBuilder.

Examples

use forceps::CacheBuilder;

let cache = CacheBuilder::new("./cache")
    .build()
    .await
    .unwrap();

Implementations

impl Cache[src]

pub async fn read<K: AsRef<[u8]>>(&self, key: K) -> Result<Vec<u8>>[src]

Reads an entry from the database, returning a vector of bytes that represent the entry.

Not Found

If the entry is not found, then it will return Err(Error::NotFound).

Examples

use forceps::CacheBuilder;

let cache = CacheBuilder::new("./cache")
    .build()
    .await
    .unwrap();

let value = cache.read(b"MY_KEY").await.unwrap();
assert_eq!(&value, b"Hello World");

pub async fn write<K: AsRef<[u8]>, V: AsRef<[u8]>>(
    &self,
    key: K,
    value: V
) -> Result<()>
[src]

Writes an entry with the specified key to the cache database. This will replace the previous entry if it exists, otherwise it will store a completely new one.

Examples

use forceps::CacheBuilder;

let cache = CacheBuilder::new("./cache")
    .build()
    .await
    .unwrap();

cache.write(b"MY_KEY", b"Hello World").await.unwrap();

pub fn read_metadata<K: AsRef<[u8]>>(&self, key: K) -> Result<Metadata>[src]

Queries the index database for metadata on the entry with the corresponding key.

This will return the metadata for the associated key. For information about what metadata is stored, look at Metadata.

Non-Async

Note that this function is not an async call. This is because the backend database used, sled, is not async-compatible. However, these calls are instead very fast.

Not Found

If the entry is not found, then it will return Err(Error::NotFound).

Examples

use forceps::CacheBuilder;

let cache = CacheBuilder::new("./cache")
    .build()
    .await
    .unwrap();

let meta = cache.read_metadata(b"MY_KEY").unwrap();
assert_eq!(meta.get_size(), b"Hello World".len() as u64);

pub fn metadata_iter(&self) -> impl Iterator<Item = Result<(Vec<u8>, Metadata)>>[src]

An iterator over the entire metadata database, which provides metadata for every entry.

This iterator provides every key in the database and the associated metadata for that key. This is not an iterator over the actual values of the database.

Non-Async

Note that this function is not an async call. This is because the backend database used, sled, is not async-compatible. However, these calls are instead very fast.

Examples

use forceps::CacheBuilder;

let cache = CacheBuilder::new("./cache")
    .build()
    .await
    .unwrap();

for result in cache.metadata_iter() {
    let (key, meta) = result.unwrap();
    println!("{}", String::from_utf8_lossy(&key))
}

Trait Implementations

impl Debug for Cache[src]

Auto Trait Implementations

impl !RefUnwindSafe for Cache

impl Send for Cache

impl Sync for Cache

impl Unpin for Cache

impl !UnwindSafe for Cache

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,