Page:
cache redis Overview
Pages
Home
ai Overview
ai gemini Overview
api HowTo
api Overview
api client HowTo
api client Overview
api server HowTo
api server Overview
api server express HowTo
app HowTo
app Overview
auth HowTo
auth Overview
auth basic HowTo
auth basic Overview
auth firebase HowTo
auth firebase Overview
auth oidc Overview
auth pocketbase HowTo
auth pocketbase Overview
auth supabase HowTo
auth supabase Overview
backend HowTo
backend Overview
backend firestore Overview
backend migrations Overview
backend postgres Overview
backend restapi Overview
backend restapi recipes Overview
backend sqlite HowTo
backend sqlite Overview
cache Overview
cache redis Overview
cloudwrapper HowTo
cloudwrapper Overview
cloudwrapper firebase HowTo
cloudwrapper firebase Overview
cloudwrapper supabase HowTo
cloudwrapper supabase Overview
code Overview
code github Overview
core HowTo
core Overview
core cli HowTo
core cli Overview
gateway upstream express HowTo
gateway upstream express Overview
i18n HowTo
i18n Overview
i18n en HowTo
i18n en Overview
i18n fr HowTo
i18n fr Overview
log HowTo
log Overview
messaging HowTo
messaging Overview
messaging firebase HowTo
messaging firebase Overview
queue HowTo
queue Overview
queue amqp HowTo
queue amqp Overview
queue aws HowTo
queue aws Overview
queue gcp HowTo
queue gcp Overview
storage HowTo
storage Overview
storage firebase HowTo
storage firebase Overview
storage local Overview
storage s3 HowTo
storage s3 Overview
storage supabase HowTo
storage supabase Overview
studio Overview
testing Overview
types HowTo
types Overview
ui Overview
ui form react Overview
ui list HowTo
ui list Overview
ui list react HowTo
ui list react Overview
worker HowTo
worker Overview
No results
1
cache redis Overview
GitHub Action edited this page 2026-05-21 19:42:21 +00:00
@quatrain/cache-redis
A dedicated Redis integration package for the Quatrain ecosystem.
Overview
This package provides a standardized RedisManager along with specialized services and middlewares to handle caching and invalidation using Redis.
Features
- 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.
HOWTO
1. Spinning up a Local Redis
Run the provided Docker composition from within the package directory:
docker-compose -f docker-compose.redis.yml up -d
2. Using the Cache Invalidation Middleware
import { 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:*`
3. Using the Redis Media Cache
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' })
Core Documentation
Foundations
Storage, Data & Cache
- backend
- backend-firestore
- backend-postgres
- backend-sqlite
- backend-migrations
- storage
- storage-firebase
- storage-s3
- storage-supabase
- storage-local
- cache
- cache-redis
Queue & Messaging
Auth & Cloud
- auth
- auth-firebase
- auth-supabase
- auth-oidc
- auth-pocketbase
- cloudwrapper
- cloudwrapper-firebase
- cloudwrapper-supabase