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 🙏

© 2025 – Pkg Stats / Ryan Hefner

strapi-cache

v1.7.0

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 and Redis caching

🚀 Installation

Install via npm or yarn:

npm install strapi-cache

or

yarn add strapi-cache

⚙️ Configuration

In your Strapi project, navigate to config/plugins.js and add the following configuration:

// 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)
    excludeRoutes: ['/api/products/private'], // (NEW) 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' or 'redis')
    redisConfig: env('REDIS_URL', 'redis://localhost:6379'), // Redis config takes either a string or an object see https://github.com/redis/ioredis for references to what object is available, the object or string is passed directly to ioredis client (if using Redis)
    redisClusterNodes: [], // If provided any cluster node (this list is not empty), initialize ioredis redis cluster client. Each object must have keys 'host' and 'port'. See https://github.com/redis/ioredis for references
    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
    autoPurgeCacheOnStart: true, // Automatically purge cache on Strapi startup
    disableAdminPopups: false, // Disable popups in the admin panel
  },
},

🔍 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 or Redis, depending on the configuration.
  • Packages: Uses lru-cache for in-memory cache. Uses ioredis for Redis caching.
  • Automatic Invalidation: Cache is cleared automatically when content is updated, deleted, or created. (GraphQL cache clears on any content update.)
  • 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. You can customize which content types to cache in the config (only for GET requests).

🔮 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.