Wraps Payload's database operations with a Redis cache built on ioredis. Read operations such as find, findOne, count and findGlobal are served from Redis when enabled, and write operations invalidate related keys by pattern. Caching is configured per collection or global with custom TTLs, and requires Payload 3.37 or higher and a Redis server.
Redis Plugin for PayloadCMS v3
Installation
npm i payloadcms-redis-plugin15
Stars
1
Forks
1
Open Issues
1 years ago
Last Updated
185
Weekly Downloads
v0.2.17
npm Version
88.4 KB
Unpacked Size
1
Dependencies
150 since Sep 6
| Date | Stars |
|---|---|
| Dec 5, 2026 | 15 |
| Dec 4, 2026 | 15 |
| Dec 3, 2026 | 15 |
| Dec 2, 2026 | 15 |
| Dec 1, 2026 | 15 |
| Nov 30, 2026 | 15 |
| Nov 29, 2026 | 15 |
| Nov 28, 2026 | 15 |
| Nov 27, 2026 | 15 |
| Nov 26, 2026 | 15 |
| Nov 25, 2026 | 15 |
| Nov 24, 2026 | 15 |
| Nov 23, 2026 | 15 |
| Nov 22, 2026 | 15 |
| Nov 21, 2026 | 15 |
| Nov 20, 2026 | 15 |
| Nov 19, 2026 | 15 |
| Nov 18, 2026 | 15 |
| Nov 17, 2026 | 15 |
| Nov 16, 2026 | 15 |
| Nov 15, 2026 | 15 |
| Nov 14, 2026 | 15 |
| Nov 13, 2026 | 15 |
| Nov 12, 2026 | 15 |
| Nov 11, 2026 | 15 |
| Nov 10, 2026 | 15 |
| Nov 9, 2026 | 15 |
| Nov 8, 2026 | 15 |
| Nov 7, 2026 | 15 |
| Nov 6, 2026 | 15 |
| Nov 5, 2026 | 15 |
| Nov 4, 2026 | 15 |
| Nov 3, 2026 | 15 |
| Nov 2, 2026 | 15 |
| Nov 1, 2026 | 15 |
| Oct 31, 2026 | 15 |
| Oct 30, 2026 | 15 |
| Oct 29, 2026 | 15 |
| Oct 28, 2026 | 15 |
| Oct 27, 2026 | 15 |
| Oct 26, 2026 | 15 |
| Oct 25, 2026 | 15 |
| Oct 24, 2026 | 15 |
| Oct 23, 2026 | 15 |
| Oct 22, 2026 | 15 |
| Oct 21, 2026 | 15 |
| Oct 20, 2026 | 15 |
| Oct 19, 2026 | 15 |
| Oct 18, 2026 | 15 |
| Oct 17, 2026 | 15 |
| Oct 16, 2026 | 15 |
| Oct 15, 2026 | 15 |
| Oct 14, 2026 | 15 |
| Oct 13, 2026 | 15 |
| Oct 12, 2026 | 15 |
| Oct 11, 2026 | 15 |
| Oct 10, 2026 | 15 |
| Oct 9, 2026 | 15 |
| Oct 8, 2026 | 15 |
| Oct 7, 2026 | 15 |
| Oct 6, 2026 | 15 |
| Oct 5, 2026 | 15 |
| Oct 4, 2026 | 15 |
| Oct 3, 2026 | 15 |
| Oct 2, 2026 | 15 |
| Oct 1, 2026 | 15 |
| Sep 30, 2026 | 15 |
| Sep 29, 2026 | 15 |
| Sep 28, 2026 | 15 |
| Sep 27, 2026 | 15 |
| Sep 26, 2026 | 15 |
| Sep 25, 2026 | 15 |
| Sep 24, 2026 | 15 |
| Sep 23, 2026 | 15 |
| Sep 22, 2026 | 15 |
| Sep 21, 2026 | 15 |
| Sep 20, 2026 | 15 |
| Sep 19, 2026 | 15 |
| Sep 18, 2026 | 15 |
| Sep 17, 2026 | 15 |
| Sep 16, 2026 | 15 |
| Sep 15, 2026 | 15 |
| Sep 14, 2026 | 15 |
| Sep 13, 2026 | 15 |
| Sep 12, 2026 | 15 |
| Sep 11, 2026 | 15 |
| Sep 10, 2026 | 15 |
| Sep 9, 2026 | 15 |
| Sep 8, 2026 | 15 |
| Sep 7, 2026 | 15 |
| Sep 6, 2026 | 15 |
139+15 since Sep 6
| Date | Weekly downloads |
|---|---|
| Dec 5, 2026 | 139 |
| Dec 4, 2026 | 153 |
| Dec 3, 2026 | 150 |
| Dec 2, 2026 | 123 |
| Dec 1, 2026 | 124 |
| Nov 30, 2026 | 134 |
| Nov 29, 2026 | 150 |
| Nov 28, 2026 | 139 |
| Nov 27, 2026 | 113 |
| Nov 26, 2026 | 113 |
| Nov 25, 2026 | 114 |
| Nov 24, 2026 | 113 |
| Nov 23, 2026 | 111 |
| Nov 22, 2026 | 89 |
| Nov 21, 2026 | 100 |
| Nov 20, 2026 | 114 |
| Nov 19, 2026 | 121 |
| Nov 18, 2026 | 123 |
| Nov 17, 2026 | 118 |
| Nov 16, 2026 | 115 |
| Nov 15, 2026 | 127 |
| Nov 14, 2026 | 153 |
| Nov 13, 2026 | 154 |
| Nov 12, 2026 | 172 |
| Nov 11, 2026 | 176 |
| Nov 10, 2026 | 181 |
| Nov 9, 2026 | 178 |
| Nov 8, 2026 | 181 |
| Nov 7, 2026 | 149 |
| Nov 6, 2026 | 136 |
| Nov 5, 2026 | 147 |
| Nov 4, 2026 | 169 |
| Nov 3, 2026 | 178 |
| Nov 2, 2026 | 339 |
| Nov 1, 2026 | 323 |
| Oct 31, 2026 | 331 |
| Oct 30, 2026 | 323 |
| Oct 29, 2026 | 272 |
| Oct 28, 2026 | 235 |
| Oct 27, 2026 | 223 |
| Oct 26, 2026 | 57 |
| Oct 25, 2026 | 83 |
| Oct 24, 2026 | 77 |
| Oct 23, 2026 | 60 |
| Oct 22, 2026 | 138 |
| Oct 21, 2026 | 153 |
| Oct 20, 2026 | 150 |
| Oct 19, 2026 | 155 |
| Oct 18, 2026 | 128 |
| Oct 17, 2026 | 118 |
| Oct 16, 2026 | 127 |
| Oct 15, 2026 | 67 |
| Oct 14, 2026 | 93 |
| Oct 13, 2026 | 99 |
| Oct 12, 2026 | 138 |
| Oct 11, 2026 | 152 |
| Oct 10, 2026 | 159 |
| Oct 9, 2026 | 160 |
| Oct 8, 2026 | 148 |
| Oct 7, 2026 | 113 |
| Oct 6, 2026 | 106 |
| Oct 5, 2026 | 65 |
| Oct 4, 2026 | 64 |
| Oct 3, 2026 | 70 |
| Oct 2, 2026 | 90 |
| Oct 1, 2026 | 101 |
| Sep 30, 2026 | 105 |
| Sep 29, 2026 | 128 |
| Sep 28, 2026 | 147 |
| Sep 27, 2026 | 142 |
| Sep 26, 2026 | 135 |
| Sep 25, 2026 | 141 |
| Sep 24, 2026 | 147 |
| Sep 23, 2026 | 154 |
| Sep 22, 2026 | 154 |
| Sep 21, 2026 | 146 |
| Sep 20, 2026 | 151 |
| Sep 19, 2026 | 178 |
| Sep 18, 2026 | 170 |
| Sep 17, 2026 | 177 |
| Sep 16, 2026 | 173 |
| Sep 15, 2026 | 150 |
| Sep 14, 2026 | 149 |
| Sep 13, 2026 | 173 |
| Sep 12, 2026 | 178 |
| Sep 11, 2026 | 166 |
| Sep 10, 2026 | 168 |
| Sep 9, 2026 | 176 |
| Sep 8, 2026 | 176 |
| Sep 7, 2026 | 164 |
| Sep 6, 2026 | 124 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1083913111-root)<a href="https://payloaddirectory.dev/plugins/1083913111-root"><img src="https://payloaddirectory.dev/badge/1083913111-root.svg" alt="Payload Directory"></a>README
A transparent Redis caching layer plugin for Payload CMS v3 that automatically caches database queries to improve performance.
npm install payloadcms-redis-plugin ioredis
# or
yarn add payloadcms-redis-plugin ioredis
# or
pnpm add payloadcms-redis-plugin ioredis
import { buildConfig } from 'payload'
import { redisCache } from 'payloadcms-redis-plugin'
export default buildConfig({
plugins: [
redisCache({
// Connect via URL
redis: {
url: 'redis://localhost:6379',
},
// Enable caching for specific collections
collections: {
posts: true,
articles: true,
},
}),
],
// ... rest of your config
})
import { Redis } from 'ioredis'
import { redisCache } from 'payloadcms-redis-plugin'
const redisClient = new Redis({
host: 'localhost',
port: 6379,
password: 'your-password',
db: 0,
})
export default buildConfig({
plugins: [
redisCache({
// Use existing client
redis: {
client: redisClient,
},
collections: {
posts: true,
},
}),
],
})
type RedisPluginConfig = {
// Redis connection (provide either client or url)
redis: { client: Redis; url?: never } | { client?: never; url: string }
// Collections to cache
collections?: Partial<Record<CollectionSlug, CacheOptions | true>>
// Globals to cache
globals?: Partial<Record<GlobalSlug, CacheOptions | true>>
// Enable debug logging
debug?: boolean
// Default cache behavior
defaultCacheOptions?: {
generateKey?: (operation: string, args: DBOperationArgs) => string
keyPrefix?: string
ttl?: number // in seconds, default: 300 (5 minutes)
}
}
type CacheOptions = {
key?: string // Custom cache key override
skip?: boolean // Skip cache for this collection/query
tags?: string[] // Tags for grouped invalidation (future feature)
ttl?: number // Time-to-live in seconds
}
redisCache({
redis: {
url: process.env.REDIS_URL,
},
// Configure collections with custom TTL
collections: {
posts: {
ttl: 600, // Cache posts for 10 minutes
skip: false,
},
articles: {
ttl: 1800, // Cache articles for 30 minutes
},
users: true, // Use default TTL (5 minutes)
},
// Cache global configurations
globals: {
settings: true,
},
// Custom default options
defaultCacheOptions: {
keyPrefix: 'myapp',
ttl: 300,
generateKey: (operation, args) => {
// Custom key generation logic
const { slug, where, locale } = args
return `${slug}:${operation}:${locale || 'default'}:${JSON.stringify(where)}`
},
},
// Enable debug logging
debug: true,
})
Override cache behavior for individual requests:
// Skip cache for a specific query
const freshPosts = await payload.find({
collection: 'posts',
req: {
context: {
cache: {
skip: true, // Bypass cache, always hit database
},
},
},
})
// Custom TTL for a specific query
const shortLivedPosts = await payload.find({
collection: 'posts',
req: {
context: {
cache: {
ttl: 60, // Cache for 1 minute only
},
},
},
})
// Custom cache key
const customCachedPosts = await payload.find({
collection: 'posts',
req: {
context: {
cache: {
key: 'posts:featured',
},
},
},
})
The following database operations are automatically cached:
Read Operations (cached before hitting database):
find - Query collections with paginationfindOne - Query single document by IDfindGlobal - Query global configurationsfindGlobalVersions - Query global version historycount - Count documentscountVersions - Count document versionscountGlobalVersions - Count global versionsqueryDrafts - Query draft documentsWrite Operations (invalidate cache after database update):
create - Create new documentcreateMany - Batch createupdateOne - Update single documentupdateMany - Batch updatedeleteOne - Delete single documentdeleteMany - Batch deleteupsert - Create or updateupdateGlobal - Update global configupdateGlobalVersion - Update global versiondeleteVersions - Delete document versionsBy default, cache keys are generated using MD5 hashing:
[prefix]:[slug]:[operation]:[md5-hash]
The hash includes: { slug, locale, operation, where }
Example keys:
posts:find:a1b2c3d4e5f6g7h8
myapp:articles:count:x9y8z7w6v5u4t3s2
Read Operations:
Request → Check cache config → Check skip flag
↓ (cache enabled)
Check Redis → HIT: Return cached → MISS: Hit DB → Store in Redis → Return
↓ (cache disabled/skipped)
Hit DB directly
Write Operations:
Request → Execute on DB → Get cache config → Check skip flag
↓ (cache enabled)
Invalidate pattern → Return result
↓ (cache disabled/skipped)
Return result directly
When data changes, the plugin automatically invalidates related cache entries using pattern matching:
// Creating a post invalidates all post queries
await payload.create({
collection: 'posts',
data: { title: 'New Post' },
})
// Invalidates: posts:*, myapp:*:posts:*, etc.
// Updating an article invalidates all article queries
await payload.update({
collection: 'articles',
id: '123',
data: { title: 'Updated' },
})
// Invalidates: articles:*, myapp:*:articles:*, etc.
Enable debug logging to monitor cache behavior:
redisCache({
redis: { url: 'redis://localhost:6379' },
collections: { posts: true },
debug: true,
})
Console output:
[RedisPlugin] [find] [posts] Cache HIT
[RedisPlugin] [find] [articles] Cache MISS
[RedisPlugin] [create] [posts] Invalidating pattern: posts:*
[RedisPlugin] [update] [posts] Cache SKIP (per-request)
The plugin includes full TypeScript definitions and extends Payload's RequestContext type:
declare module 'payload' {
export interface RequestContext {
cache?: {
key?: string
skip?: boolean
tags?: string[]
ttl?: number
}
}
}
redis.keys() for invalidation (consider SCAN in production with large keyspaces)# Install dependencies
pnpm install
# Run development server
pnpm dev
# Run tests
pnpm test
# Build plugin
pnpm build
# Lint code
pnpm lint
redisCache({
redis: { url: process.env.REDIS_URL },
collections: {
products: { ttl: 3600 }, // Cache products for 1 hour
categories: { ttl: 7200 }, // Cache categories for 2 hours
orders: { skip: true }, // Never cache orders
customers: { ttl: 600 }, // Cache customers for 10 minutes
},
globals: {
siteSettings: { ttl: 86400 }, // Cache site settings for 24 hours
},
})
redisCache({
redis: { url: process.env.REDIS_URL },
collections: {
posts: { ttl: 1800 }, // Cache posts for 30 minutes
authors: { ttl: 3600 }, // Cache authors for 1 hour
comments: { ttl: 300 }, // Cache comments for 5 minutes
},
defaultCacheOptions: {
keyPrefix: 'blog',
ttl: 600,
},
debug: process.env.NODE_ENV === 'development',
})
// Test Redis connection
const redis = new Redis('redis://localhost:6379')
await redis.ping() // Should return 'PONG'
skip: true is setredis-cli info memoryContributions are welcome! Please see the GitHub repository for issues and pull requests.
MIT
Isaiah Anyimi pls hire me
payload upstash
Upstash Redis key-value adapter for Payload's built-in KV store
82333/wk7v3 v4
payload kv
Store counters, feeds and expiring data in Redis or KV stores while querying them as normal Payload fields
771.4k/wk0v3 v4
payload cache
Automatic Next.js 16 and Vercel cache tagging and invalidation for Payload reads
74321/wk0v3 v4
payload kv cloudflare
Payload KV adapter that stores key-value data in Cloudflare Workers KV
6663/wk0v3 v4
payload revalidate
Field-driven Next.js cache revalidation for Payload with id-keyed cached finders and a dependency map
59240/wk18v3
cached local api
Cache Payload Local API operations with Next.js unstable_cache and automatic tag-based revalidation
48112/wk335v3