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

Commit

Permalink
feat(chore): add default versioning & hostname on cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-arnoult committed Feb 17, 2022
1 parent 59b6c56 commit 678ffd6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import Redis from 'redis-tag-cache';
import crypto from 'crypto';

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

export default function RedisCache (options) {
const client = new Redis(options.redisConfig);

return {
async invoke({ route, render, getTags }) {
const key = `page:${ route }`;
async invoke({ route, context, render, getTags }) {
const version = options.version || defaultVersion
const hostname = context.req.hostname

const key = `${ version }:page:${ hostname }${ route }`;
const cachedResponse = await client.get(key);

if (cachedResponse) {
Expand Down

0 comments on commit 678ffd6

Please sign in to comment.