Expand description
Cache invalidation via PostgreSQL LISTEN/NOTIFY
This module provides distributed cache invalidation using PostgreSQL’s LISTEN/NOTIFY feature. When one WarpDrive instance invalidates a cache entry, all other instances are notified via PostgreSQL and can clear their local caches.
§Architecture
Instance A Instance B
┌────────┐ ┌────────┐
│ DELETE │ │ │
│ key │ │ │
└───┬────┘ └───▲────┘
│ │
│ ┌──────────────┐ │
└───►│ PostgreSQL │─────────┘
│ NOTIFY │
│ "key=foo" │
└──────────────┘§Example
use warpdrive::cache::coordinator::CacheCoordinator;
use warpdrive::cache::invalidation::InvalidationListener;
use warpdrive::config::Config;
let config = Config::from_env()?;
let cache = CacheCoordinator::from_config(&config).await?;
// Start listener in background (if PostgreSQL configured)
if let Some(db_url) = &config.database_url {
InvalidationListener::spawn(
db_url.clone(),
config.pg_channel_cache_invalidation.clone(),
cache.clone(),
);
}Structs§
- Invalidation
Listener - Cache invalidation listener
- Invalidation
Message - Cache invalidation message format