Skip to content

Commit 0e20085

Browse files
committed
Cache cleaner endpoint path
1 parent 373a2c1 commit 0e20085

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ modules: [
1818
'@luispittagros/nuxt-ssr-redis-cache',
1919
{
2020
enabled: true,
21-
expireTime: 60 * 60,
21+
ttl: 60 * 60,
2222
client: {
2323
socket: {
2424
host: '127.0.0.1',
2525
port: 6379,
2626
},
2727
password: null,
2828
},
29-
matches: [/^\/$/, '/articles/'],
29+
paths: [/^\/$/, '/articles/'],
3030
cacheCleanEndpoint: {
3131
enabled: false,
3232
path: '/ssr-redis-cache',
@@ -43,15 +43,15 @@ or
4343
modules: ['@luispittagros/nuxt-ssr-redis-cache'],
4444
ssrRedisCache: {
4545
enabled: true,
46-
expireTime: 60 * 60,
46+
ttl: 60 * 60,
4747
client: {
4848
socket: {
4949
host: '127.0.0.1',
5050
port: 6379,
5151
},
5252
password: null,
5353
},
54-
matches: [/^\/$/, '/articles/'],
54+
paths: [/^\/$/, '/articles/'],
5555
cacheCleanEndpoint: {
5656
enabled: true,
5757
path: '/ssr-redis-cache',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@luispittagros/nuxt-ssr-redis-cache",
3-
"version": "1.0.6",
3+
"version": "1.0.8",
44
"description": "Blazing Fast SSR page renderings using Redis.",
55
"main": "src/cache.js",
66
"author": "Luís Pitta Grós",

src/cache.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default async function nuxtRedisCache(moduleOptions) {
3030
const isCacheCleanEndpointEnabled = options.cacheCleanEndpoint && options.cacheCleanEndpoint.enabled !== false
3131

3232
if (isCacheCleanEndpointEnabled) {
33-
this.addServerMiddleware(ssrRedisCacheMiddleware(client, options.cacheCleanEndpoint))
33+
this.addServerMiddleware({ path: options.cacheCleanEndpoint.path || '/ssr-redis-cache', handler: ssrRedisCacheMiddleware(client, options.cacheCleanEndpoint)})
3434
}
3535

3636
console.log('[Nuxt SSR Redis Cache]:', 'Cache clean endpoint is ' + (isCacheCleanEndpointEnabled ? 'enabled\x1b[32m ✔' : 'disabled\x1b[31m ✘') + '\n')
@@ -41,7 +41,7 @@ export default async function nuxtRedisCache(moduleOptions) {
4141

4242
renderer.renderRoute = async function (route, context) {
4343
// Check if the route is cacheable, if not, just render the route (cache-control: no-cache is set when the browser cache is disabled)
44-
if (!isCacheable(route, options.matches, context.req.headers['cache-control'])) {
44+
if (!isCacheable(route, options.paths, context.req.headers['cache-control'])) {
4545
return renderRoute(route, context)
4646
}
4747

@@ -72,9 +72,9 @@ export default async function nuxtRedisCache(moduleOptions) {
7272
context.res.setHeader('X-Cache', hitCache ? 'HIT' : 'MISS')
7373
}
7474

75-
if (!hitCache && isCacheable(url, options.matches)) {
75+
if (!hitCache && isCacheable(url, options.paths)) {
7676
client.set('nuxt/route::' + url, serialize(result), {
77-
EX: options.expireTime,
77+
EX: options.ttl,
7878
})
7979
}
8080
})
@@ -90,8 +90,8 @@ function buildOptions(moduleOptions) {
9090
},
9191
password: null,
9292
},
93-
expireTime: 60 * 60,
94-
matches: [],
93+
ttl: 60 * 60,
94+
paths: [],
9595
cacheCleanEndpoint: {
9696
enabled: false,
9797
path: '/ssr-redis-cache',
@@ -102,8 +102,8 @@ function buildOptions(moduleOptions) {
102102
return Object.assign({}, defaultOptions, moduleOptions)
103103
}
104104

105-
function isCacheable(url, matches = [], cacheControl = null) {
106-
return cacheControl !== 'no-cache' && matches.some((path) => (path instanceof RegExp ? path.test(url) : url.startsWith(path)))
105+
function isCacheable(url, paths = [], cacheControl = null) {
106+
return cacheControl !== 'no-cache' && paths.some((path) => (path instanceof RegExp ? path.test(url) : url.startsWith(path)))
107107
}
108108

109109
module.exports.meta = require('../package.json')

src/serverMiddleware.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function ssrRedisCacheMiddleware(redisClient, options = {}) {
88
app.use(json())
99
app.use(cors(options.cors || {}))
1010

11-
app.post(options.path || '/ssr-redis-cache', async (req, res) => {
11+
app.post('/', async (req, res) => {
1212
const { paths = [] } = req.body
1313

1414
if (!paths.length) {

0 commit comments

Comments
 (0)