SineCache
SineCache is a high-performance, in-memory caching library for Rust, designed to efficiently store and manage key-value pairs with support for various eviction policies and persistence options using Append-Only Files (AOF).
Features
Powerful Caching Mechanism
SineCache provides a robust caching solution with flexible configurations and support for multiple eviction policies, ensuring optimal performance for varying application needs.
Eviction Policies
Choose from FIFO (First-In, First-Out), LRU (Least Recently Used), and LFU (Least Frequently Used) eviction policies. Additionally, define custom eviction policies through a simple trait implementation.
Asynchronous Support
- AsyncCache: Wraps the
Cachestruct with atokio::sync::Mutex, enabling safe concurrent access with asynchronous operations (asyncversions ofget,put,remove, etc.).
Persistence with Append-Only Files (AOF)
Optionally persist cache data using AOF, ensuring durability and recovery of cache state across application restarts. If flush_time is provided (milliseconds), data is flushed to disk after every flush_time milliseconds to disk without blocking the main thread. In case of None, every operation is flushed to disk in the same thread.
Thread Safety
Ensures thread safety with appropriate locking mechanisms (tokio::sync::Mutex for AsyncCache), making it suitable for multi-threaded environments.
Configuration Flexibility
Configure cache size limits, eviction policies, AOF settings, and more through intuitive configuration structs (CacheSyncConfig and AsyncCacheConfig).
Comprehensive Documentation
Extensive API documentation and examples facilitate easy integration and customization within applications.
Safety and Reliability
Built with Rust's ownership model and type system, ensuring memory safety and preventing common bugs like null pointer dereferencing and data races.
Getting Started
To use SineCache in your Rust project, add it to your Cargo.toml:
[]
= "0.2.0"
Examples
Some examples are listed below but for the more detailed documentation, visit: https://docs.rs/sine_cache/latest/sine_cache/
Cache - Synchronous Cache:
Simple methods related to Cache . For using it in concurrent environment, customize on top of it like wrapping in Mutex and using async methods etc.
use ;
AsyncCache - Asynchronous Cache:
Some examples related to AsyncCache are listed below:
-
Without
AOF:When
AOFis not required:
use ;
async
-
With
AOF:When AOF is required, we can pass details related to AOF in the configurations and set the periodic flushes to disk or each operation record to disk based on setting
flush_timein milliseconds orNone.
use ;
async
Custom eviction policy
Custom evicton policies can also be defined and used with all the features of AsyncCache and Cache.
use EvictionPolicy;
use ;
async
Planned Features
AOF Compaction Periodically
Compact AOF files periodically to stop the append only file becoming too large.
License
This project is licensed under the MIT License - see the LICENSE file for details.