threadsafe-lru
This is a thread-safe implementation of an LRU (Least Recently Used) cache in Rust.
The LruCache struct uses sharding to improve concurrency by splitting the cache into multiple smaller segments, each protected by a mutex.
Example Usage
use LruCache;
In this example, a new LruCache is created with 4 shards and a capacity of 2 entries per shard.
Items are inserted using the insert method.
The get method retrieves an item by key, promoting it to the most recently used position.
Finally, the remove method deletes an item from the cache.
This implementation ensures that operations on different keys can be performed concurrently without causing race conditions due to shared state.
API Documentation
For detailed documentation, including all methods and usage examples, refer to the LruCache API on docs.rs.
Testing
LruCache is thoroughly tested with a suite of unit tests covering various operations. You can run the tests using cargo test:
This ensures that all functionalities work as expected and helps maintain high code quality.
License
LruCache is licensed under the MIT license. See LICENSE for more details.