-
Notifications
You must be signed in to change notification settings - Fork 1
cache redis Overview
GitHub Action edited this page May 21, 2026
·
1 revision
A dedicated Redis integration package for the Quatrain ecosystem.
This package provides a standardized RedisManager along with specialized services and middlewares to handle caching and invalidation using Redis.
-
RedisManager: A singleton wrapper around
ioredisthat provides a standardized client. -
RedisCacheInvalidationMiddleware: A Quatrain
BackendMiddlewarethat intercepts successful backend mutations (afterExecute) to invalidate specific cache namespaces matching the collection being modified. -
RedisMediaCache: A proxy layer over any
@quatrain/storageStorageAdapterdesigned to cache media files. It caches binary files into Redis with a short TTL, providing a stable immutable source that an API can stream to clients with permanentCache-Controlheaders. -
Docker Compose snippet: A ready-to-use
docker-compose.redis.ymlis provided in the repository root for local development.
Run the provided Docker composition from within the package directory:
docker-compose -f docker-compose.redis.yml up -dimport { Backend } from '@quatrain/backend'
import { SQLiteAdapter } from '@quatrain/backend-sqlite'
import { RedisManager, RedisCacheInvalidationMiddleware } from '@quatrain/cache-redis'
const redis = RedisManager.getInstance('redis://localhost:6379')
const invalidationMiddleware = new RedisCacheInvalidationMiddleware(redis, 'my-namespace')
const sqlite = new SQLiteAdapter(...)
sqlite.addMiddleware(invalidationMiddleware)
Backend.init(sqlite)
// Now, every time Backend.create, Backend.update, or Backend.delete is called,
// the middleware will run AFTER the commit and execute `DEL my-namespace:collectionName:*`import { LocalStorageAdapter } from '@quatrain/storage-local'
import { RedisManager, RedisMediaCache } from '@quatrain/cache-redis'
const storage = new LocalStorageAdapter(...)
const redis = RedisManager.getInstance()
// Cache binaries for 10 minutes (600s)
const mediaCache = new RedisMediaCache(storage, redis, 600)
// Fetching a media file directly buffers it from Redis if available,
// or falls back to downloading via the StorageAdapter and storing it in Redis.
const buffer = await mediaCache.getMedia({ ref: 'my-file.jpg' })