Crate titanium_cache

Crate titanium_cache 

Source
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 DashMap for concurrent read/write access
  • TTL Support: Automatic expiration of stale entries (default: 1 hour)
  • Garbage Collection: InMemoryCache::sweep removes 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::sweep periodically
  • Implementing a custom Cache trait with Redis/database backing

Structs§

InMemoryCache
In-memory cache for Discord entities with Time-To-Live (TTL).

Traits§

Cache
Trait for cache implementations.