strapi-cache 1.11.2 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -72,7 +72,7 @@ Full configuration example:
72
72
  size: 1024 * 1024 * 1024, // Maximum size of the cache (1 GB) (only for memory cache)
73
73
  allowStale: false, // Allow stale cache items (only for memory cache)
74
74
  cacheableRoutes: ['/api/products', '/api/categories'], // Caches routes which start with these paths (if empty array, all '/api' routes are cached)
75
- // keyGenerator: (ctx) => `${ctx.request.method}:${ctx.request.url}`, // (Optional) custom cache key for REST + GraphQL requests; receives koa ctx
75
+ // keyGenerator: (ctx, defaultKey) => `custom:${defaultKey}`, // (Optional) custom cache key for REST + GraphQL requests; receives koa ctx and the generated default key
76
76
  // 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
77
77
  excludeRoutes: ['/api/products/private'], // Exclude routes which start with these paths from being cached (takes precedence over cacheableRoutes). **Note:** `excludeRoutes` takes precedence over `cacheableRoutes`.
78
78
  provider: 'memory', // Cache provider ('memory', 'redis' or 'valkey')
@@ -98,32 +98,32 @@ Full configuration example:
98
98
 
99
99
  Possible configuration keys are listed below; omitted keys keep the plugin defaults.
100
100
 
101
- | Key | Description | Possible values |
102
- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
103
- | `debug` | Log cache decisions and operations to the server console | `true` or `false` (default: `false`) |
104
- | `provider` | Where entries are stored | `'memory'`, `'redis'`, or `'valkey'` (default: `'memory'`) |
105
- | `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 |
106
- | `redisClusterNodes` | Seed nodes for Redis cluster mode; non-empty list switches to a cluster client | Array of `{ host: string, port: number }` (default: `[]`) |
107
- | `redisClusterOptions` | Options for the cluster client (e.g. `scaleReads`); `redisOptions` often come from `redisConfig` | Object (default: `{}`) |
108
- | `redisScanDeleteCount` | `COUNT` hint for `SCAN` when purging keys (Redis/Valkey) | Positive number (default: `100`) |
109
- | `max` | Maximum number of entries (in-memory provider only) | Positive integer (default: `1000`) |
110
- | `ttl` | Time-to-live for each entry, in milliseconds | Non-negative number (default: `3600000`, i.e. 1 hour) |
111
- | `size` | Approximate max total size in bytes (in-memory provider only) | Positive integer (default: `10485760`, i.e. 10 MB) |
112
- | `allowStale` | Whether stale entries may be returned (in-memory provider only) | `true` or `false` (default: `false`) |
113
- | `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”) |
114
- | `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) |
115
- | `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` |
116
- | `excludeRoutes` | URLs starting with any of these prefixes are **never** cached; evaluated before `cacheableRoutes` / entities | Array of path prefix strings (default: `[]`) |
117
- | `cacheHeaders` | Store and replay response headers with the body | `true` or `false` (default: `true`) |
118
- | `cacheHeadersDenyList` | Header names (lowercase) to strip when `cacheHeaders` is `true` | Array of strings (default: `[]`) |
119
- | `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: `[]`) |
120
- | `cacheAuthorizedRequests` | Whether to cache requests that include an `Authorization` header | `true` or `false` (default: `false`) |
121
- | `cacheGetTimeoutInMs` | Max time to wait for a cache read before treating it as a miss | Milliseconds (default: `1000`) |
122
- | `autoPurgeCache` | Invalidate relevant REST cache entries after content create/update/delete | `true` or `false` (default: `true`) |
123
- | `autoPurgeGraphQL` | Invalidate GraphQL cache after content create/update/delete | `true` or `false` (default: `false` if omitted; set `true` to enable) |
124
- | `autoPurgeCacheOnStart` | Clear the cache when Strapi starts | `true` or `false` (default: `true`) |
125
- | `disableAdminPopups` | Turn off admin UI notifications for cache actions | `true` or `false` (default: `false`) |
126
- | `disableAdminButtons` | Hide manual purge controls in the admin (list and edit views), either globally or for specific REST content type paths | `true`, `false`, or an array of paths such as `['/api/products', '/api/tags']` (default: `false`) |
101
+ | Key | Description | Possible values |
102
+ | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------- |
103
+ | `debug` | Log cache decisions and operations to the server console | `true` or `false` (default: `false`) |
104
+ | `provider` | Where entries are stored | `'memory'`, `'redis'`, or `'valkey'` (default: `'memory'`) |
105
+ | `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 |
106
+ | `redisClusterNodes` | Seed nodes for Redis cluster mode; non-empty list switches to a cluster client | Array of `{ host: string, port: number }` (default: `[]`) |
107
+ | `redisClusterOptions` | Options for the cluster client (e.g. `scaleReads`); `redisOptions` often come from `redisConfig` | Object (default: `{}`) |
108
+ | `redisScanDeleteCount` | `COUNT` hint for `SCAN` when purging keys (Redis/Valkey) | Positive number (default: `100`) |
109
+ | `max` | Maximum number of entries (in-memory provider only) | Positive integer (default: `1000`) |
110
+ | `ttl` | Time-to-live for each entry, in milliseconds | Non-negative number (default: `3600000`, i.e. 1 hour) |
111
+ | `size` | Approximate max total size in bytes (in-memory provider only) | Positive integer (default: `10485760`, i.e. 10 MB) |
112
+ | `allowStale` | Whether stale entries may be returned (in-memory provider only) | `true` or `false` (default: `false`) |
113
+ | `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”) |
114
+ | `keyGenerator` | Custom function to build cache keys; receives Koa `ctx` and the generated default key (for REST: `${method}:${url}`, for GraphQL: a hash-based default key); when omitted, the plugin uses the generated default key; for GraphQL, if set, the ctx gets additional fields: `rootFields` and `operationName` which may be useful for invalidation logic | Function `(ctx, defaultKey) => string` (default: unset) |
115
+ | `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` |
116
+ | `excludeRoutes` | URLs starting with any of these prefixes are **never** cached; evaluated before `cacheableRoutes` / entities | Array of path prefix strings (default: `[]`) |
117
+ | `cacheHeaders` | Store and replay response headers with the body | `true` or `false` (default: `true`) |
118
+ | `cacheHeadersDenyList` | Header names (lowercase) to strip when `cacheHeaders` is `true` | Array of strings (default: `[]`) |
119
+ | `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: `[]`) |
120
+ | `cacheAuthorizedRequests` | Whether to cache requests that include an `Authorization` header | `true` or `false` (default: `false`) |
121
+ | `cacheGetTimeoutInMs` | Max time to wait for a cache read before treating it as a miss | Milliseconds (default: `1000`) |
122
+ | `autoPurgeCache` | Invalidate relevant REST cache entries after content create/update/delete | `true` or `false` (default: `true`) |
123
+ | `autoPurgeGraphQL` | Invalidate GraphQL cache after content create/update/delete | `true` or `false` (default: `false` if omitted; set `true` to enable) |
124
+ | `autoPurgeCacheOnStart` | Clear the cache when Strapi starts | `true` or `false` (default: `true`) |
125
+ | `disableAdminPopups` | Turn off admin UI notifications for cache actions | `true` or `false` (default: `false`) |
126
+ | `disableAdminButtons` | Hide manual purge controls in the admin (list and edit views), either globally or for specific REST content type paths | `true`, `false`, or an array of paths such as `['/api/products', '/api/tags']` (default: `false`) |
127
127
 
128
128
  ## 🔍 Routes
129
129
 
@@ -182,24 +182,24 @@ const bootstrap = ({ strapi: strapi2 }) => {
182
182
  loggy.info("Plugin initialized");
183
183
  strapi2.admin.services.permission.actionProvider.registerMany(actions);
184
184
  };
185
- const getCustomCacheKey = (context, keyGenerator) => {
185
+ const getCustomCacheKey = (context, keyGenerator, fallbackKey) => {
186
186
  if (typeof keyGenerator !== "function") {
187
187
  return void 0;
188
188
  }
189
- const customKey = keyGenerator(context);
189
+ const customKey = keyGenerator(context, fallbackKey);
190
190
  if (typeof customKey === "string") {
191
191
  return customKey;
192
192
  }
193
193
  return void 0;
194
194
  };
195
- const resolveGraphqlCacheKey = (context, fallbackKey, keyGenerator) => getCustomCacheKey(context, keyGenerator) ?? fallbackKey;
195
+ const resolveGraphqlCacheKey = (context, fallbackKey, keyGenerator) => getCustomCacheKey(context, keyGenerator, fallbackKey) ?? fallbackKey;
196
196
  const generateCacheKey = (context, keyGenerator) => {
197
- const customKey = getCustomCacheKey(context, keyGenerator);
197
+ const { url } = context.request;
198
+ const { method } = context.request;
199
+ const customKey = getCustomCacheKey(context, keyGenerator, `${method}:${url}`);
198
200
  if (customKey !== void 0) {
199
201
  return customKey;
200
202
  }
201
- const { url } = context.request;
202
- const { method } = context.request;
203
203
  return `${method}:${url}`;
204
204
  };
205
205
  const generateGraphqlCacheKey = (payload, method = "POST", rootFields = [], strapi2) => {
@@ -178,24 +178,24 @@ const bootstrap = ({ strapi: strapi2 }) => {
178
178
  loggy.info("Plugin initialized");
179
179
  strapi2.admin.services.permission.actionProvider.registerMany(actions);
180
180
  };
181
- const getCustomCacheKey = (context, keyGenerator) => {
181
+ const getCustomCacheKey = (context, keyGenerator, fallbackKey) => {
182
182
  if (typeof keyGenerator !== "function") {
183
183
  return void 0;
184
184
  }
185
- const customKey = keyGenerator(context);
185
+ const customKey = keyGenerator(context, fallbackKey);
186
186
  if (typeof customKey === "string") {
187
187
  return customKey;
188
188
  }
189
189
  return void 0;
190
190
  };
191
- const resolveGraphqlCacheKey = (context, fallbackKey, keyGenerator) => getCustomCacheKey(context, keyGenerator) ?? fallbackKey;
191
+ const resolveGraphqlCacheKey = (context, fallbackKey, keyGenerator) => getCustomCacheKey(context, keyGenerator, fallbackKey) ?? fallbackKey;
192
192
  const generateCacheKey = (context, keyGenerator) => {
193
- const customKey = getCustomCacheKey(context, keyGenerator);
193
+ const { url } = context.request;
194
+ const { method } = context.request;
195
+ const customKey = getCustomCacheKey(context, keyGenerator, `${method}:${url}`);
194
196
  if (customKey !== void 0) {
195
197
  return customKey;
196
198
  }
197
- const { url } = context.request;
198
- const { method } = context.request;
199
199
  return `${method}:${url}`;
200
200
  };
201
201
  const generateGraphqlCacheKey = (payload, method = "POST", rootFields = [], strapi2) => {
@@ -1,7 +1,7 @@
1
1
  import { Core } from '@strapi/strapi';
2
2
  import { Context } from 'koa';
3
- export type CacheKeyGenerator = (context: Context) => string;
4
- export declare const getCustomCacheKey: (context: Context, keyGenerator?: CacheKeyGenerator) => string;
3
+ export type CacheKeyGenerator = (context: Context, defaultKey?: string) => string;
4
+ export declare const getCustomCacheKey: (context: Context, keyGenerator?: CacheKeyGenerator, fallbackKey?: string) => string;
5
5
  export declare const resolveGraphqlCacheKey: (context: Context, fallbackKey: string, keyGenerator?: CacheKeyGenerator) => string;
6
6
  export declare const generateCacheKey: (context: Context, keyGenerator?: CacheKeyGenerator) => string;
7
7
  export declare const generateGraphqlCacheKey: (payload: string, method?: 'GET' | 'POST', rootFields?: string[], strapi?: Core.Strapi) => string;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.11.2",
2
+ "version": "1.12.0",
3
3
  "keywords": [
4
4
  "strapi cache",
5
5
  "strapi rest cache",