rtcache
A high-performance, thread-safe caching library for Rust with built-in TTL support and web UI monitoring.
Features
- 🚀 High Performance: Built on Tokio for async/await support
- 🔒 Thread-Safe: Fully concurrent and safe for multi-threaded environments
- ⏱️ TTL Support: Automatic cache entry expiration
- 📊 Web UI: Built-in monitoring interface
- 🔄 Automatic Pruning: Background task for cache maintenance
- 🎯 Type-Safe: Generic implementation supporting any key-value types
- 🔌 Extensible: Customizable storage backends via the
Storetrait
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Quick Start
use Duration;
use ;
use Result;
// Implement your storage backend
;
async
Key Concepts
Cache Entry States
The cache maintains entries in one of three states:
Fetching: Entry is currently being fetchedFetchFailed: Previous fetch attempt failedNode: Valid cache entry with value
Features in Detail
- Automatic TTL: Cache entries are automatically removed after their TTL expires
- Concurrent Access: Multiple threads can safely access the cache simultaneously
- Web UI: Monitor cache statistics and performance through a built-in web interface
- Background Pruning: Automatic cleanup of expired entries
- Error Handling: Robust error handling with
anyhowintegration
API Reference
Main Types
Cache<K, V>: The main cache typeStore<K, V>: Trait for implementing custom storage backendsGetError: Error type for cache retrieval failures
Key Methods
Cache::new(store, ttl): Create a new cache instanceCache::get(key): Retrieve a value (fetches if not cached)Cache::insert(key, value): Manually insert a valueCache::remove(key): Remove a value from the cacheCache::try_evict(key): Attempt to evict a specific entryCache::evict_all_sync(): Remove all entries from the cache
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.