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 🙏

© 2026 – Pkg Stats / Ryan Hefner

strapi-cache

v1.10.1

Published

An LRU-Cache plugin for strapi v5

Readme

🧠 strapi-cache

A powerful LRU-Cache plugin for Strapi v5 Boost your API performance with automatic in-memory or Redis caching for REST and GraphQL requests.

npm version Strapi Version License: MIT npm


✨ Features

  • ⚡️ Cache REST API responses
  • 🔮 Cache GraphQL queries
  • ♻️ LRU (Least Recently Used) caching strategy
  • 🔧 Simple integration with Strapi config
  • 📦 Lightweight with zero overhead
  • 🗄️ Supports in-memory, Redis and Valkey caching

🚀 Installation

Install via npm or yarn:

npm install strapi-cache

or

yarn add strapi-cache

Quickstart

// config/plugins.{js,ts}
'strapi-cache': {
  enabled: true,
},

To use Redis or Valkey instead of memory, set provider and redisConfig (required for those providers):

// config/plugins.{js,ts}
'strapi-cache': {
  enabled: true,
  config: {
    provider: 'redis', // or 'valkey'
    redisConfig: env('REDIS_URL', 'redis://127.0.0.1:6379'),
  },
},

See ioredis (Redis) or iovalkey (Valkey) for advanced redisConfig shapes (URL string or client options object).

Full configuration example:

// config/plugins.{js,ts}
'strapi-cache': {
  enabled: true,
  config: {
    debug: false, // Enable debug logs
    max: 1000, // Maximum number of items in the cache (only for memory cache)
    ttl: 1000 * 60 * 60, // Time to live for cache items (1 hour)
    size: 1024 * 1024 * 1024, // Maximum size of the cache (1 GB) (only for memory cache)
    allowStale: false, // Allow stale cache items (only for memory cache)
    cacheableRoutes: ['/api/products', '/api/categories'], // Caches routes which start with these paths (if empty array, all '/api' routes are cached)
    // keyGenerator: (ctx) => `${ctx.request.method}:${ctx.request.url}`, // (Optional) custom cache key for REST + GraphQL requests; receives koa ctx
    // cacheableEntities: ['products', 'categories'], // (Optional) Specify which entities to cache. When set, only these entities will be cached (ignores cacheableRoutes). If not set (undefined), cacheableRoutes logic is used
    excludeRoutes: ['/api/products/private'], // Exclude routes which start with these paths from being cached (takes precedence over cacheableRoutes). **Note:** `excludeRoutes` takes precedence over `cacheableRoutes`.
    provider: 'memory', // Cache provider ('memory', 'redis' or 'valkey')
    redisConfig: env('REDIS_URL', 'redis://localhost:6379'), // Redis/Valkey config: string or object. See https://github.com/redis/ioredis (Redis) or https://github.com/valkey-io/iovalkey (Valkey)
    redisClusterNodes: [], // If provided any cluster node (this list is not empty), initialize cluster client. Each object must have keys 'host' and 'port'
    redisClusterOptions: {}, // Options for ioredis redis cluster client. redisOptions key is taken from redisConfig parameter above if not set here. See https://github.com/redis/ioredis for references
    cacheHeaders: true, // Plugin also stores response headers in the cache (set to false if you don't want to cache headers)
    cacheHeadersDenyList: ['access-control-allow-origin', 'content-encoding'], // Headers to exclude from the cache (must be lowercase, if empty array, no headers are excluded, cacheHeaders must be true)
    cacheHeadersAllowList: ['content-type', 'content-security-policy'], // Headers to include in the cache (must be lowercase, if empty array, all headers are cached, cacheHeaders must be true)
    cacheAuthorizedRequests: false, // Cache requests with authorization headers (set to true if you want to cache authorized requests)
    cacheGetTimeoutInMs: 1000, // Timeout for getting cached data in milliseconds (default is 1 second)
    autoPurgeCache: true, // Automatically purge cache on content CRUD operations
    autoPurgeGraphQL: true, // Automatically purge GraphQL cache on content CRUD operations
    autoPurgeCacheOnStart: true, // Automatically purge cache on Strapi startup
    disableAdminPopups: false, // Disable popups in the admin panel
    disableAdminButtons: false, // Disable the purge cache buttons in the admin panel (list view and edit view)
  },
},

⚙️ Configuration

Possible configuration keys are listed below; omitted keys keep the plugin defaults.

| Key | Description | Possible values | | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | | debug | Log cache decisions and operations to the server console | true or false (default: false) | | provider | Where entries are stored | 'memory', 'redis', or 'valkey' (default: 'memory') | | redisConfig | Redis/Valkey connection: URL string or client options passed to ioredis/iovalkey | String or object; required when provider is 'redis' or 'valkey'. Default: value of REDIS_URL from the environment | | redisClusterNodes | Seed nodes for Redis cluster mode; non-empty list switches to a cluster client | Array of { host: string, port: number } (default: []) | | redisClusterOptions | Options for the cluster client (e.g. scaleReads); redisOptions often come from redisConfig | Object (default: {}) | | redisScanDeleteCount | COUNT hint for SCAN when purging keys (Redis/Valkey) | Positive number (default: 100) | | max | Maximum number of entries (in-memory provider only) | Positive integer (default: 1000) | | ttl | Time-to-live for each entry, in milliseconds | Non-negative number (default: 3600000, i.e. 1 hour) | | size | Approximate max total size in bytes (in-memory provider only) | Positive integer (default: 10485760, i.e. 10 MB) | | allowStale | Whether stale entries may be returned (in-memory provider only) | true or false (default: false) | | cacheableRoutes | Only URLs starting with one of these paths are cached; if empty, every URL under the REST API prefix matches | Array of path prefix strings (default: [] meaning “all API routes”) | | keyGenerator | Custom function to build REST cache keys; receives Koa ctx; when omitted, default key is ${method}:${url}; for graphql, if set, the ctx gets additional fields: rootFields and operationName which may be useful for invalidation logic | Function (ctx) => string (default: unset) | | cacheableEntities | If non-empty, only these API “entity” segments are cached; when set, this drives eligibility instead of cacheableRoutes | Array of strings (e.g. collection/table names), or omit / leave empty to use cacheableRoutes | | excludeRoutes | URLs starting with any of these prefixes are never cached; evaluated before cacheableRoutes / entities | Array of path prefix strings (default: []) | | cacheHeaders | Store and replay response headers with the body | true or false (default: true) | | cacheHeadersDenyList | Header names (lowercase) to strip when cacheHeaders is true | Array of strings (default: []) | | cacheHeadersAllowList | If non-empty, only these header names (lowercase) are stored; if empty, all headers are stored (subject to deny list) | Array of strings (default: []) | | cacheAuthorizedRequests | Whether to cache requests that include an Authorization header | true or false (default: false) | | cacheGetTimeoutInMs | Max time to wait for a cache read before treating it as a miss | Milliseconds (default: 1000) | | autoPurgeCache | Invalidate relevant REST cache entries after content create/update/delete | true or false (default: true) | | autoPurgeGraphQL | Invalidate GraphQL cache after content create/update/delete | true or false (default: false if omitted; set true to enable) | | autoPurgeCacheOnStart | Clear the cache when Strapi starts | true or false (default: true) | | disableAdminPopups | Turn off admin UI notifications for cache actions | true or false (default: false) | | disableAdminButtons | Hide manual purge controls in the admin (list and edit views) | true or false (default: false) |

🔍 Routes

The plugin creates three new routes

  • POST /strapi-cache/purge-cache (purges the whole cache)
  • POST /strapi-cache/purge-cache/key (purges cache entries that have the key in the cache key, expects JSON body with key field)
  • GET /strapi-cache/cacheable-routes (returns the cacheable routes defined in the config)
  • GET /strapi-cache/config (returns the current plugin config)

All of these routes are protected by the policies admin::isAuthenticatedAdmin and plugin::strapi-cache.purge-cache. The plugin::strapi-cache.purge-cache policy can be managed in the plugin's permissions section under the settings.

🗂️ How It Works

  • Storage: The plugin keeps cached data in memory, Redis or Valkey, depending on the configuration.
  • Packages: Uses lru-cache for in-memory cache. Uses ioredis for Redis and iovalkey for Valkey caching.
  • Automatic Invalidation: When autoPurgeCache is enabled (default), relevant REST cache entries are invalidated on content create, update, or delete. When autoPurgeGraphQL is enabled, GraphQL cache is invalidated the same way (it is off unless you set it in config).
  • no-cache Header Support: Respects the no-cache header, letting you skip the cache by setting Cache-Control: no-cache in your request.
  • Default Cached Requests: By default, caches all GET requests to /api (or whatever prefix you defined) and POST requests to /graphql or predefined graphql route from graphql plugin config. You can customize which routes or entities to cache using cacheableRoutes or cacheableEntities config options.

🔮 Planned Features

  • [x] Cache Invalidation: Automatically invalidate cache on content updates, deletions, or creations.
  • [x] GraphQL Caching: Cache GraphQL queries.
  • [x] Purge Cache Button: Add a UI option in the Strapi admin panel to manually purge the cache for content-types.
  • [x] Purge Whole Cache Button: Add a UI option in the Strapi admin settings panel to purge the whole cache.
  • [x] Route/Content-Type Specific Caching: Allow users to define which routes should be cached based.
  • [x] Switchable Cache Providers: Explore support for other caching providers like Redis for distributed caching.

If you have any feature requests or suggestions, please open a dedicated issue.

🛑 Problems

If you encounter any issues, please feel free to open an issue on the GitHub repo.

🛠️ Contributing

Contributions are welcome! If you have suggestions or improvements, please open an issue or submit a pull request.