strapi-cache 1.5.8 → 1.5.9
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 +1 -1
- package/dist/server/index.js +4 -2
- package/dist/server/index.mjs +4 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -82,7 +82,7 @@ All of these routes are protected by the policies `admin::isAuthenticatedAdmin`
|
|
|
82
82
|
- **Packages**: Uses [lru-cache](https://github.com/isaacs/node-lru-cache) for in-memory cache. Uses [ioredis](https://github.com/redis/ioredis) for Redis caching.
|
|
83
83
|
- **Automatic Invalidation**: Cache is cleared automatically when content is updated, deleted, or created. (GraphQL cache clears on any content update.)
|
|
84
84
|
- **`no-cache` Header Support**: Respects the `no-cache` header, letting you skip the cache by setting `Cache-Control: no-cache` in your request.
|
|
85
|
-
- **Default Cached Requests**: By default, caches all GET requests to `/api` and POST requests to `/graphql`. You can customize which content types to cache in the config (only for GET requests).
|
|
85
|
+
- **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).
|
|
86
86
|
|
|
87
87
|
## 🔮 Planned Features
|
|
88
88
|
|
package/dist/server/index.js
CHANGED
|
@@ -34,6 +34,7 @@ const loggy = {
|
|
|
34
34
|
async function invalidateCache(event, cacheStore, strapi2) {
|
|
35
35
|
const { model } = event;
|
|
36
36
|
const uid = model.uid;
|
|
37
|
+
const restApiPrefix = strapi2.config.get("api.rest.prefix", "/api");
|
|
37
38
|
try {
|
|
38
39
|
const contentType = strapi2.contentType(uid);
|
|
39
40
|
if (!contentType || !contentType.kind) {
|
|
@@ -41,7 +42,7 @@ async function invalidateCache(event, cacheStore, strapi2) {
|
|
|
41
42
|
return;
|
|
42
43
|
}
|
|
43
44
|
const pluralName = contentType.kind === "singleType" ? contentType.info.singularName : contentType.info.pluralName;
|
|
44
|
-
const apiPath =
|
|
45
|
+
const apiPath = `${restApiPrefix}/${pluralName}`;
|
|
45
46
|
const regex = new RegExp(`^.*:${apiPath}(/.*)?(\\?.*)?$`);
|
|
46
47
|
await cacheStore.clearByRegexp([regex]);
|
|
47
48
|
loggy.info(`Invalidated cache for ${apiPath}`);
|
|
@@ -195,13 +196,14 @@ const middleware$1 = async (ctx, next) => {
|
|
|
195
196
|
const cacheEntry = await cacheStore.get(key);
|
|
196
197
|
const cacheControlHeader = ctx.request.headers["cache-control"];
|
|
197
198
|
const noCache = cacheControlHeader && cacheControlHeader.includes("no-cache");
|
|
199
|
+
const restApiPrefix = strapi.config.get("api.rest.prefix", "/api");
|
|
198
200
|
const routeIsExcluded = excludeRoutes.some((route) => url.startsWith(route));
|
|
199
201
|
if (routeIsExcluded) {
|
|
200
202
|
loggy.info(`Route excluded from cache: ${url}`);
|
|
201
203
|
await next();
|
|
202
204
|
return;
|
|
203
205
|
}
|
|
204
|
-
const routeIsCachable = cacheableRoutes.some((route) => url.startsWith(route)) || cacheableRoutes.length === 0 && url.startsWith(
|
|
206
|
+
const routeIsCachable = cacheableRoutes.some((route) => url.startsWith(route)) || cacheableRoutes.length === 0 && url.startsWith(restApiPrefix);
|
|
205
207
|
const authorizationHeader = ctx.request.headers["authorization"];
|
|
206
208
|
if (authorizationHeader && !cacheAuthorizedRequests) {
|
|
207
209
|
loggy.info(`Authorized request bypassing cache: ${key}`);
|
package/dist/server/index.mjs
CHANGED
|
@@ -30,6 +30,7 @@ const loggy = {
|
|
|
30
30
|
async function invalidateCache(event, cacheStore, strapi2) {
|
|
31
31
|
const { model } = event;
|
|
32
32
|
const uid = model.uid;
|
|
33
|
+
const restApiPrefix = strapi2.config.get("api.rest.prefix", "/api");
|
|
33
34
|
try {
|
|
34
35
|
const contentType = strapi2.contentType(uid);
|
|
35
36
|
if (!contentType || !contentType.kind) {
|
|
@@ -37,7 +38,7 @@ async function invalidateCache(event, cacheStore, strapi2) {
|
|
|
37
38
|
return;
|
|
38
39
|
}
|
|
39
40
|
const pluralName = contentType.kind === "singleType" ? contentType.info.singularName : contentType.info.pluralName;
|
|
40
|
-
const apiPath =
|
|
41
|
+
const apiPath = `${restApiPrefix}/${pluralName}`;
|
|
41
42
|
const regex = new RegExp(`^.*:${apiPath}(/.*)?(\\?.*)?$`);
|
|
42
43
|
await cacheStore.clearByRegexp([regex]);
|
|
43
44
|
loggy.info(`Invalidated cache for ${apiPath}`);
|
|
@@ -191,13 +192,14 @@ const middleware$1 = async (ctx, next) => {
|
|
|
191
192
|
const cacheEntry = await cacheStore.get(key);
|
|
192
193
|
const cacheControlHeader = ctx.request.headers["cache-control"];
|
|
193
194
|
const noCache = cacheControlHeader && cacheControlHeader.includes("no-cache");
|
|
195
|
+
const restApiPrefix = strapi.config.get("api.rest.prefix", "/api");
|
|
194
196
|
const routeIsExcluded = excludeRoutes.some((route) => url.startsWith(route));
|
|
195
197
|
if (routeIsExcluded) {
|
|
196
198
|
loggy.info(`Route excluded from cache: ${url}`);
|
|
197
199
|
await next();
|
|
198
200
|
return;
|
|
199
201
|
}
|
|
200
|
-
const routeIsCachable = cacheableRoutes.some((route) => url.startsWith(route)) || cacheableRoutes.length === 0 && url.startsWith(
|
|
202
|
+
const routeIsCachable = cacheableRoutes.some((route) => url.startsWith(route)) || cacheableRoutes.length === 0 && url.startsWith(restApiPrefix);
|
|
201
203
|
const authorizationHeader = ctx.request.headers["authorization"];
|
|
202
204
|
if (authorizationHeader && !cacheAuthorizedRequests) {
|
|
203
205
|
loggy.info(`Authorized request bypassing cache: ${key}`);
|
package/package.json
CHANGED