[−][src]Crate actix_sled_cache
Actix Sled Cache
A caching system built on top of Sled and Actix
This project is designed to allow easy caching in actix-based systems. Specifically, it was developed to hold image files and metadata in a media cache for a simple web application.
Example:
use actix::{Actor, System}; use actix_sled_cache::bincode::Cache; use sled_extensions::Config; let sys = System::new("cache-example"); let db = Config::default().temporary(true).open()?; let mut cache_builder = Cache::builder(db, "simple-cache"); cache_builder .as_mut() .extend_on_update() .extend_on_fetch() .expiration_length(chrono::Duration::seconds(1)); let cache: Cache<usize> = cache_builder .frequency(std::time::Duration::from_secs(1)) .build()?; // Clone the tree out of the cache before starting the cache actor let tree = cache.tree(); cache.start(); // If un-accessed, this record will be deleted after one second tree.insert("some-key", 5)?; // Commented to prevent a never-ending test // sys.run()?;
The cache created here has a frequency of one second, which means every second it will check for expired records. In many cases, the frequency can be much less often. This cache also has an expiration_length of one second, which means after one second has passed since the last interaction with the record, it is eligible for deletion.
Modules
bin | A pure bytes-backed cache for binary data |
bincode | A bincode-backed cache for structured data |
Structs
Cache | A cache backed by Sled and Actix, storing data via the Encoding trait from sled_extensions |
CacheBuilder | A builder for caches |
Deleted | A message containing the key ov an item that has been deleted from a cache |
Subscribe | A message that registers an actor's interest in cache expiry |
Enums
Error | The error type for the cache |