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

Commit 4c691ec

Browse files
committed
refactor config with fallback version
1 parent a255f3a commit 4c691ec

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import Redis from 'redis-tag-cache';
22
import crypto from 'crypto';
3+
import { Logger } from '@vue-storefront/core'
34

4-
const defaultVersion = crypto.randomBytes(15).toString('hex')
55

66
export default function RedisCache (options) {
7-
const client = new Redis(options.redisConfig);
7+
const { version, ...redisConfig } = options;
8+
9+
const client = new Redis(redisConfig);
10+
const fallbackVersion = crypto.randomBytes(15).toString('hex')
811

912
return {
1013
async invoke({ route, context, render, getTags }) {
11-
const version = options.version || defaultVersion
14+
const cacheVersion = version || fallbackVersion
1215
const hostname = context.req.hostname
1316

14-
const key = `${ version }:page:${ hostname }${ route }`;
17+
if (!version) {
18+
Logger.warn('The `version` property is missing in the `@vue-storefront/redis-cache` package configuration. In a multi-instance setup, this will result in a separate cache for every instance. Please refer to Redis driver documentation for more details.');
19+
}
20+
21+
const key = `${ cacheVersion }:page:${ hostname }${ route }`;
1522
const cachedResponse = await client.get(key);
1623

1724
if (cachedResponse) {

0 commit comments

Comments
 (0)