Expand description
Titanium Cache - High-performance in-memory cache for Discord entities.
This crate provides InMemoryCache for caching Discord entities like
guilds, channels, users, and members.
§Features
- Lock-Free Concurrency: Uses
DashMapfor concurrent read/write access - TTL Support: Automatic expiration of stale entries (default: 1 hour)
- Garbage Collection:
InMemoryCache::sweepremoves expired entries - Arc-Wrapped Values: Cheap cloning for multi-consumer scenarios
§Example
use titanium_cache::{Cache, InMemoryCache};
use std::time::Duration;
use std::sync::Arc;
// Create cache with custom TTL
let cache = InMemoryCache::with_ttl(Duration::from_secs(600));
// Insert and retrieve (example with mock data)
// cache.insert_user(Arc::new(user));
// let user = cache.user(user_id);§Memory Management
The cache stores all entities in memory. For large bots, consider:
- Using shorter TTL values
- Calling
InMemoryCache::sweepperiodically - Implementing a custom
Cachetrait with Redis/database backing
Structs§
- InMemory
Cache - In-memory cache for Discord entities with Time-To-Live (TTL).
Traits§
- Cache
- Trait for cache implementations.