Registry / web-framework / strapi-plugin-rest-cache

strapi-plugin-rest-cache

JSON →
library4.2.9jsnpmunverified

The Strapi REST Cache Plugin is a community-maintained solution for accelerating HTTP requests within Strapi applications by implementing a caching layer. It utilizes a provider-based architecture, allowing developers to choose from various storage backends like in-memory, Redis, or file system for caching responses. The plugin supports configurable caching strategies and features automatic invalidation of cached data when related content types are updated, mitigating issues with stale data. While the provided metadata indicates version 4.2.9, the latest significant release is v5.0.0, which introduced breaking changes for Strapi v5 compatibility. The project maintains an active development cadence, with frequent updates addressing bugs and adding features, aiming to improve Strapi API performance. It differentiates itself by its flexible provider system and automatic cache invalidation tied to Strapi content updates.

npm install strapi-plugin-rest-cache
INSTALL
IMPORT
SIG · STRAPI-PLUGIN-REST
S
strapi-plugin-rest-cache
web-frameworkjavascriptv4.2.9
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

plugins
module.exports = { 'rest-cache': { enabled: true, config: { /* ... */ } } };
import { RestCachePlugin } from 'strapi-plugin-rest-cache';
Strapi plugins are typically enabled and configured directly in `config/plugins.js` or `src/plugins/rest-cache/admin/src/index.js` as an object within the `module.exports`, not imported as ES modules or CommonJS modules in application code directly.
RestCacheConfig
// No direct import for configuration. Configuration is defined in config/plugins.js
Configuration is handled via standard Strapi plugin configuration patterns in `config/plugins.js`. There isn't a direct TypeScript type import for the plugin's configuration object itself from the plugin's main entry point, although internal types exist.
RestCacheProvider
const memoryProvider = require('@strapi-community/provider-rest-cache-memory');
import { MemoryProvider } from '@strapi-community/plugin-rest-cache';
Providers are separate packages and are either required directly for advanced configuration or specified by name in the plugin's configuration. They are not typically imported from the main `plugin-rest-cache` package.

This quickstart demonstrates how to enable the `rest-cache` plugin in a Strapi v4/v5 application using an in-memory provider and configure basic caching for specific content types in `config/plugins.js`.

module.exports = { // ... other plugins 'rest-cache': { enabled: true, config: { provider: { name: 'memory', options: { max: 32767, // max number of items in cache maxAge: 3600, // cache expiration time in seconds }, }, strategy: { contentTypes: [ // List of content types to cache 'api::article.article', 'api::category.category', ], maxAge: 3600, // global maxAge for content types hitpass: false, // If true, cache will not be used if query params are present }, }, }, // ... };
Debug
Known issues
breakingThe `strapi-plugin-rest-cache` package name changed to `@strapi-community/plugin-rest-cache` in v5.0.0. Additionally, all provider packages (e.g., `strapi-provider-rest-cache-memory`) were renamed to their `@strapi-community` scoped equivalents.
fix
Update your `package.json` to use the new scoped package names (`@strapi-community/plugin-rest-cache`, `@strapi-community/provider-rest-cache-*`) and reinstall dependencies. Adjust any internal references in configuration files.
affects: >=5.0.0
breakingThe Couchbase Provider was entirely removed in v5.0.0 due to lack of maintenance and testing resources.
fix
If you were using the Couchbase Provider, you must migrate to an alternative provider such as Redis or implement a custom provider. There is no direct replacement within the plugin for Couchbase.
affects: >=5.0.0
gotchaThe README explicitly states the package is currently under 'ALPHA' status, indicating potential instability, API changes without major version bumps, or incomplete features. While v5.0.0 is released, this warning from the README for prior versions implies ongoing development and refinement.
fix
Exercise caution, thoroughly test in development environments, and monitor the official GitHub repository for updates and breaking changes. Consider this for any version based on README warnings.
affects: >=4.0.0 <5.0.0
gotchaThis plugin is specifically for Strapi v4.x.x and v5.x.x. It is not compatible with Strapi v3.x. The recommended alternative for Strapi v3.x is `strapi-middleware-cache`.
fix
Ensure your Strapi project is on version 4 or higher. For Strapi v3, use `strapi-middleware-cache` instead.
affects: <4.0.0
Errors
Common errors & fixes
Error: Cannot find module 'strapi-plugin-rest-cache'
The package name for the plugin has changed in Strapi v5.
fix
Ensure you are using the correct package name `@strapi-community/plugin-rest-cache` in your `package.json` and in your Strapi plugin configuration file (e.g., `config/plugins.js`).
TypeError: Cannot read properties of undefined (reading 'config') at module.exports
The plugin is enabled but misconfigured, often missing the `provider` or `strategy` objects, or having incorrect syntax.
fix
Review your `config/plugins.js` file for the `rest-cache` entry. Ensure that `enabled: true` is set and that the `config` object correctly defines a `provider` and `strategy` with valid options, including `name` for the provider.
Cache is not being purged automatically when content types are updated.
This typically happens if the `strategy.contentTypes` array is not correctly configured to include the relevant content types, or if the content types are not properly exposed via the REST API.
fix
Verify that the `contentTypes` array in your plugin configuration's `strategy` includes the exact API ID of the content types you expect to be purged. E.g., `['api::article.article']`.
Upgrade
Version history
4.2.9latest on npm
Audit
Dependencies
@strapi/strapirequiredPeer dependency for Strapi application core functionality.
@strapi-community/provider-rest-cache-memoryoptionalRequired for in-memory caching functionality, often installed by default.
@strapi-community/provider-rest-cache-redisoptionalRequired for Redis caching functionality.
Agent activity
21 hits · last 30 days
node
18
Meta
1
OpenAI (training)
1
Resources