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.
Getting Started
Features
Mulitple Eviction Policies
Supports FIFO (First In, First Out), LRU (Least Recently Used), and LFU (Least Frequently Used) eviction policies out of the box.
Customizable
Define your own eviction policies by implementing a simple trait, enabling tailored cache behavior to suit specific application needs.
Efficient Memory Management
Optimizes memory usage by using references (KeyRef) to keys stored in the cache, reducing redundancy and improving performance.
Async/Await and Concurrency Support
The library provides two structs for in-memory caching:
- Cache: This struct implements various eviction policies for in-memory caching without using locks. Users have the flexibility to implement their own locking mechanisms if needed.
- ThreadSafeCache: This struct wraps the
Cachestruct with atokio::sync::Mutex, enabling safe concurrent access. It offersasyncversions of methods likegetandputto support asynchronous operations. The mutex ensures thread safety, making it suitable for concurrent environments.
Getting Started
To use SineCache in your Rust project, add it to your Cargo.toml:
[]
= "0.1.0"
Examples
Cache
use Cache;
use LFU;
This example demonstrates basic usage of SineCache with LFU eviction policy. You can easily switch to other eviction policies like FIFO or LRU by replacing LFU::new() with the desired policy constructor.
ThreadSafeCache
use ThreadSafeCache;
use LFU;
async
License
This project is licensed under the MIT License - see the LICENSE file for details.