@extravirgin/debounced-cache-clearer
TypeScript icon, indicating that this package has built-in type declarations

1.0.13 • Public • Published

Debounced Cache Clearer Plugin for Payload CMS 3.0

The Debounced Cache Clearer plugin for Payload CMS 3.0 automatically clears cache for specified collections after a defined debounce time. Additionally, it offers the ability to manually trigger cache deletion.

Features

  • Automatic Cache Clearing: Clears cache after a specified debounce time following any changes (update, or delete) to specified collections. The debounce time can be customized.
  • Manual Cache Deletion: Provides a UI button in the admin panel for manually triggering cache deletion.
  • Configurable: Customize debounce time, revalidation URL, and cache tags.
  • Flexible Collection Support: Choose specific collections to enable cache clearing on.

Installation

  1. Clone or copy this plugin into your project.
  2. Install the necessary dependencies.
  3. Import and use the plugin in your Payload CMS setup.

Usage

In your payload.config.ts (or JavaScript equivalent), use the plugin like this:

import { debouncedCacheClearer } from 'path/to/debounced-cache-clearer';

export default {
  plugins: [
    debouncedCacheClearer({
      activeCollections: ['pages', 'offices'], // Specify collections to target
      revalidateUrl: `${process.env.NEXT_PUBLIC_FRONTEND_URL}/api/revalidate`, // The URL for revalidation API
      tags: ['global'], // Cache tags
      revalidateKey: process.env.REVALIDATE_KEY ?? '', // Revalidate key for security
      debounceTime: 600, // Debounce time in seconds (default: 600 seconds)
    }),
  ],
}

Setting Up the Cron Job

In order to make the system work automatically, we need to set up a cron job to trigger the API endpoint at regular intervals. The cron job will make a POST request to the following URL every 5 or 10 minutes:

API Endpoint

  • URL: /api/globals/ev_cache_settings/debounced-data
  • Method: POST
  • Accepted Parameter:
    • revalidateKey (required, string): The secret key used for authentication.

Note: Make sure the revalidateKey in the request matches the key configured in your Payload CMS setup to ensure secure access.

Readme

Keywords

none

Package Sidebar

Install

npm i @extravirgin/debounced-cache-clearer

Weekly Downloads

15

Version

1.0.13

License

MIT

Unpacked Size

79.8 kB

Total Files

30

Last publish

Collaborators

  • kevmiota
  • devvietswiss