bext-plugin-cache-redis
Redis L2 cache with tag-based invalidation and SWR.
Adds a Redis-backed L2 cache layer to bext's built-in response cache. Responses cached in Redis are shared across all bext instances. Supports tag-based invalidation and stale-while-revalidate.
Install
bext plugin add cache-redisConfig
[plugins.cache-redis]
redis_url = "$REDIS_URL"
ttl = "5m"
swr = "30m"
max_size = "50mb"
key_prefix = "bext:"How it works
The plugin sits between bext's in-memory L1 cache and the origin. On a cache miss in L1:
1. Check Redis (L2). If found and fresh, return it and promote to L1. 2. If stale but within SWR window, return stale and revalidate in background. 3. If miss, fetch from origin, store in both L1 and L2.
Tag invalidation
Tag your cached responses in your route handlers:
return html(body, 200, {
enabled: true,
ttl_ms: 300_000,
tags: ["product:123", "catalog"],
});Then purge by tag:
bext cache purge --tag product:123This purges matching entries from both L1 and L2.
Why nsjail?
This plugin needs network access to reach Redis. The nsjail sandbox allows controlled outbound connections while still isolating the plugin from the filesystem and other processes.