@strapi-community/provider-rest-cache-memory
v5.1.0
Published
Speed-up HTTP requests with LRU cache
Readme
Stores cache entries in the Strapi process, in an LRU bounded by entry count. This is the default provider and ships with the plugin, so you rarely need to install it yourself.
When to use it
Use it when you run one Strapi instance.
Each process holds its own cache, so with two or more instances behind a load
balancer they cache independently and a purge on one does not reach the others
— one instance serves fresh content while another serves stale. Entries are
also lost on restart. If either matters, use
@strapi-community/provider-rest-cache-redis.
Install
Already a dependency of the plugin. Install it explicitly only if you want to pin its version:
npm install @strapi-community/provider-rest-cache-memoryyarn add @strapi-community/provider-rest-cache-memorypnpm add @strapi-community/provider-rest-cache-memoryConfigure
// ./config/plugins.js
module.exports = {
"rest-cache": {
config: {
provider: {
name: "memory",
options: {
maxSize: 32767,
// Milliseconds. One hour.
ttl: 3600000,
},
},
strategy: {
contentTypes: ["api::article.article"],
},
},
},
};// ./config/plugins.ts
export default {
"rest-cache": {
config: {
provider: {
name: "memory",
options: {
maxSize: 32767,
// Milliseconds. One hour.
ttl: 3600000,
},
},
strategy: {
contentTypes: ["api::article.article"],
},
},
},
};Options
| Option | Type | Default | Description |
| --- | --- | --- | --- |
| maxSize | number | 32767 | Maximum number of entries before the least recently used one is evicted. Must be greater than 0. |
| ttl | number (ms) | — | Store-level default lifetime. In practice the plugin passes an explicit lifetime on every write from strategy.maxAge, so this is only a backstop. |
max is accepted as a legacy alias for maxSize.
Durations are milliseconds.
3600000is one hour;3600is 3.6 seconds. Set the lifetime you actually care about withstrategy.maxAge.
Documentation
License
See the LICENSE file.
