npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lukestonehm/payload-redis-cache

v1.1.7

Published

Redis cache plugin for Payload CMS

Downloads

394

Readme

Payload Redis Cache Plugin

This is a modified version of this plugin for Payload CMS that solved a particular use case I have

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

| Option| Type | Description | |---|---|---| | redisUrl * | string | Redis instance's url. | | redisNamespace | string | Choose the prefix to use for cache redis keys. Defaults to payload. | | redisIndexesName | string | Choose the index key for cache redis indexes. Defaults to payload-cache-index. | | excludedCollections | string[] | An array of collection names to be excluded. | | excludedGlobals | string[] | An array of globals names to be excluded. | | includedPaths | string[] | 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