Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.

Commit 678ffd6

Browse files
committed
feat(chore): add default versioning & hostname on cache key
1 parent 59b6c56 commit 678ffd6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import Redis from 'redis-tag-cache';
2+
import crypto from 'crypto';
23

3-
export default function RedisCache (options) {
4-
const client = new Redis(options);
4+
const defaultVersion = crypto.randomBytes(15).toString('hex')
55

6+
export default function RedisCache (options) {
7+
const client = new Redis(options.redisConfig);
8+
69
return {
7-
async invoke({ route, render, getTags }) {
8-
const key = `page:${ route }`;
10+
async invoke({ route, context, render, getTags }) {
11+
const version = options.version || defaultVersion
12+
const hostname = context.req.hostname
13+
14+
const key = `${ version }:page:${ hostname }${ route }`;
915
const cachedResponse = await client.get(key);
1016

1117
if (cachedResponse) {

0 commit comments

Comments
 (0)