Aengz

payload redis cache

by Aengz
Databases & data
v1
^1.5.9
MIT

Overview

Summary generated from the README

Adds a Redis cache layer to Payload API endpoints. Cache entries are keyed by the user's collection and the original URL. It is registered in the Payload config as a plugin and initialised with a Redis connection in the server file. It requires a Redis instance and the redis package, and targets Payload 1.x.

Features

  • Caches API endpoint responses in Redis
  • Cache key based on user collection and original URL
  • Exclude specific collections or globals from caching
  • Include custom routes through the includedPaths option
  • Configurable Redis namespace and index key name
  • invalidateCache helper to clear cached entries

Use cases

  • Reduce database load on frequently requested Payload REST endpoints
  • Speed up API responses for read-heavy sites backed by Payload 1.x
  • Clear cached responses manually after content changes

From the author

Redis cache plugin for Payload CMS

Installation

npm i @aengz/payload-redis-cache

64

Stars

13

Forks

4

Open Issues

2 years ago

Last Updated

280

Weekly Downloads

v1.1.1

npm Version

41.3 KB

Unpacked Size

0

Dependencies

GitHub stars

64+3 since Sep 6

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 202664
Dec 4, 202664
Dec 3, 202664
Dec 2, 202664
Dec 1, 202664
Nov 30, 202664
Nov 29, 202664
Nov 28, 202664
Nov 27, 202664
Nov 26, 202664
Nov 25, 202664
Nov 24, 202664
Nov 23, 202664
Nov 22, 202664
Nov 21, 202664
Nov 20, 202664
Nov 19, 202664
Nov 18, 202664
Nov 17, 202664
Nov 16, 202664
Nov 15, 202664
Nov 14, 202664
Nov 13, 202664
Nov 12, 202664
Nov 11, 202664
Nov 10, 202664
Nov 9, 202664
Nov 8, 202664
Nov 7, 202664
Nov 6, 202664
Nov 5, 202664
Nov 4, 202664
Nov 3, 202664
Nov 2, 202664
Nov 1, 202664
Oct 31, 202664
Oct 30, 202664
Oct 29, 202664
Oct 28, 202664
Oct 27, 202664
Oct 26, 202664
Oct 25, 202664
Oct 24, 202664
Oct 23, 202664
Oct 22, 202664
Oct 21, 202664
Oct 20, 202664
Oct 19, 202664
Oct 18, 202664
Oct 17, 202664
Oct 16, 202664
Oct 15, 202664
Oct 14, 202664
Oct 13, 202664
Oct 12, 202664
Oct 11, 202663
Oct 10, 202663
Oct 9, 202663
Oct 8, 202663
Oct 7, 202663
Oct 6, 202663
Oct 5, 202663
Oct 4, 202663
Oct 3, 202663
Oct 2, 202663
Oct 1, 202663
Sep 30, 202663
Sep 29, 202663
Sep 28, 202663
Sep 27, 202663
Sep 26, 202663
Sep 25, 202663
Sep 24, 202663
Sep 23, 202663
Sep 22, 202663
Sep 21, 202663
Sep 20, 202663
Sep 19, 202663
Sep 18, 202663
Sep 17, 202663
Sep 16, 202663
Sep 15, 202662
Sep 14, 202662
Sep 13, 202662
Sep 12, 202662
Sep 11, 202662
Sep 10, 202662
Sep 9, 202661
Sep 8, 202661
Sep 7, 202661
Sep 6, 202661
npm weekly downloads

260+193 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 2026260
Dec 4, 2026183
Dec 3, 2026156
Dec 2, 2026140
Dec 1, 2026114
Nov 30, 2026124
Nov 29, 202686
Nov 28, 202690
Nov 27, 2026101
Nov 26, 202689
Nov 25, 2026109
Nov 24, 2026104
Nov 23, 202694
Nov 22, 202672
Nov 21, 202675
Nov 20, 202666
Nov 19, 202675
Nov 18, 2026127
Nov 17, 2026120
Nov 16, 2026121
Nov 15, 2026119
Nov 14, 2026117
Nov 13, 2026122
Nov 12, 2026113
Nov 11, 202655
Nov 10, 202688
Nov 9, 202688
Nov 8, 202683
Nov 7, 202682
Nov 6, 202684
Nov 5, 2026101
Nov 4, 2026106
Nov 3, 202675
Nov 2, 202674
Nov 1, 202674
Oct 31, 202676
Oct 30, 202671
Oct 29, 202649
Oct 28, 202626
Oct 27, 202634
Oct 26, 202654
Oct 25, 202654
Oct 24, 202652
Oct 23, 202643
Oct 22, 202657
Oct 21, 2026115
Oct 20, 2026106
Oct 19, 202684
Oct 18, 202685
Oct 17, 202681
Oct 16, 202692
Oct 15, 202690
Oct 14, 202672
Oct 13, 202675
Oct 12, 202677
Oct 11, 202677
Oct 10, 202678
Oct 9, 202678
Oct 8, 202680
Oct 7, 202643
Oct 6, 202639
Oct 5, 202639
Oct 4, 202641
Oct 3, 202644
Oct 2, 202642
Oct 1, 202634
Sep 30, 202682
Sep 29, 202682
Sep 28, 202680
Sep 27, 202684
Sep 26, 2026116
Sep 25, 2026151
Sep 24, 2026150
Sep 23, 2026105
Sep 22, 2026114
Sep 21, 2026146
Sep 20, 2026145
Sep 19, 2026109
Sep 18, 202687
Sep 17, 202688
Sep 16, 202691
Sep 15, 202682
Sep 14, 202652
Sep 13, 202678
Sep 12, 202684
Sep 11, 202673
Sep 10, 202692
Sep 9, 202690
Sep 8, 202699
Sep 7, 202697
Sep 6, 202667

Each point is npm's rolling 7-day download count.

Health Score

48/100Fair

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/579188648-root.svg)](https://payloaddirectory.dev/plugins/579188648-root)
HTML
<a href="https://payloaddirectory.dev/plugins/579188648-root"><img src="https://payloaddirectory.dev/badge/579188648-root.svg" alt="Payload Directory"></a>
Updated Jan 10, 2024Created Dec 16, 2022Published Nov 7, 2023

README

Payload Redis Cache Plugin

This plugin for Payload CMS adds a cache layer to API endpoints. The cache is based on the combination of the user's collection and the original URL.

Requirements

  • Payload version 1.0.19 or higher is required
  • A Redis instance is required

Installation

To install the plugin, run one of the following commands:

yarn add @aengz/payload-redis-cache

or

npm install @aengz/payload-redis-cache

Redis package

You also need to install the redis package if it is not already installed:

yarn add redis

or

npm install redis

Usage

To use the plugin, add it to the Payload config as follows:

import { buildConfig } from 'payload/config';
import { cachePlugin } from '@aengz/payload-redis-cache'

const config = buildConfig({
  // your config here
  
  plugins: [
    cachePlugin({ 
      excludedCollections: ['users'],
      //  excludedGlobals: ['myglobal']
    })
  ]
})

Add the initializer function in server.ts

import { cachePlugin } from '@aengz/payload-redis-cache'

...

initRedis({
  redisUrl: process.env.REDIS_URI
})

Plugin options

OptionTypeDescription
redisUrl *stringRedis instance's url.
redisNamespacestringChoose the prefix to use for cache redis keys. Defaults to payload.
redisIndexesNamestringChoose the index key for cache redis indexes. Defaults to payload-cache-index.
excludedCollectionsstring[]An array of collection names to be excluded.
excludedGlobalsstring[]An array of globals names to be excluded.
includedPathsstring[]An array of custom routes to be included.

A * denotes that the property is required.

Helpers

This package provides utility functions for managing the cache. Here's an example of how to use the invalidateCache function:

import { invalidateCache }  from '@aengz/payload-redis-cache'

...

invalidateCache()

Development

There is a development environment in the /dev directory of the repository. To use it, create a new .env file in the /dev directory using the example .env.example file as a reference:

cd dev
cp .env.example .env

Before using the plugin in the development environment, the package needs to be built. To build the library, run one of the following commands:

Build the lib

Build the lib using:

yarn dev:build

or

npm run dev:build

Use development environment

To run the development environment, use the following command:

yarn dev

or

npm run dev

Running test

To run the test suite, use one of the following commands:

yarn test

or

npm run test

License

MIT

Similar plugins