Skip to content

Commit ac4a623

Browse files
manually add changes from #104
#104 was based on the Strapi 4 package, manually added the changes from the PR
1 parent 28b81a5 commit ac4a623

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

packages/plugin-rest-cache/server/src/middlewares/recv.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default function createRecv(options, { strapi }) {
2424
);
2525
}
2626
const store = strapi.plugin('rest-cache').service('cacheStore');
27-
const { strategy } = strapi.config.get("plugin::rest-cache");
27+
const { strategy } = strapi.config.get('plugin::rest-cache');
2828
const { cacheRouteConfig } = options;
2929
const { hitpass, maxAge, keys } = cacheRouteConfig;
3030
const { enableEtag = false, enableXCacheHeaders = false } = strategy;
@@ -34,7 +34,7 @@ export default function createRecv(options, { strapi }) {
3434
const cacheKey = generateCacheKey(ctx, keys);
3535

3636
// hitpass check
37-
const lookup = shouldLookup(ctx, hitpass);
37+
const lookup = await shouldLookup(ctx, hitpass);
3838

3939
// keep track of the etag
4040
let etagCached = null;
@@ -112,19 +112,15 @@ export default function createRecv(options, { strapi }) {
112112
// persist etag asynchronously
113113
store.set(`${cacheKey}_etag`, etag, maxAge).catch(() => {
114114
debug('strapi:plugin-rest-cache')(
115-
`[RECV] GET ${cacheKey} ${chalk.yellow(
116-
'Unable to store ETag in cache'
117-
)}`
115+
`[RECV] GET ${cacheKey} ${chalk.yellow('Unable to store ETag in cache')}`
118116
);
119117
});
120118
}
121119

122120
// persist cache asynchronously
123121
store.set(cacheKey, ctx.body, maxAge).catch(() => {
124122
debug('strapi:plugin-rest-cache')(
125-
`[RECV] GET ${cacheKey} ${chalk.yellow(
126-
'Unable to store Content in cache'
127-
)}`
123+
`[RECV] GET ${cacheKey} ${chalk.yellow('Unable to store Content in cache')}`
128124
);
129125
});
130126
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
export const shouldLookup = function (
3+
export const shouldLookup = async function (
44
ctx,
55
hitpass // @todo: function or boolean => can be optimized
66
) {
@@ -11,8 +11,8 @@ export const shouldLookup = function (
1111
}
1212

1313
if (type === 'function') {
14-
return !hitpass(ctx);
14+
return !(await hitpass(ctx));
1515
}
1616

1717
return false;
18-
}
18+
};

0 commit comments

Comments
 (0)