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]
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]
&self,
key: K,
value: V
) -> Result<()>
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
Auto Trait Implementations
impl !RefUnwindSafe for Cache
impl !RefUnwindSafe for Cacheimpl !UnwindSafe for Cache
impl !UnwindSafe for Cache