Anvil.ForgeBridge.Cached (Anvil v0.1.1)
View SourceCaching wrapper for ForgeBridge backends.
Adds TTL-based caching layer on top of any ForgeBridge backend to improve performance and reduce load on Forge. Best for hybrid deployments where sample content is relatively stable.
Configuration
# config/config.exs
config :anvil,
forge_bridge_backend: Anvil.ForgeBridge.Cached,
forge_bridge_primary_backend: Anvil.ForgeBridge.Direct,
forge_cache_ttl: :timer.minutes(15)Features
- TTL-based expiration (default 15 minutes)
- Cache warming for hot queues
- Graceful degradation (serve stale on backend failure)
- Telemetry events for cache hits/misses
Cache Invalidation
Subscribe to sample update events for proactive invalidation:
Phoenix.PubSub.subscribe(Forge.PubSub, "sample_updates")
def handle_info({:sample_updated, sample_id}, state) do
Anvil.ForgeBridge.Cached.invalidate(sample_id)
{:noreply, state}
end
Summary
Functions
Clears the entire sample cache.
Invalidates a cached sample by ID.
Warms the cache for a list of sample IDs.