Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import Redis from 'redis-tag-cache';
import crypto from 'crypto';
import { Logger } from '@vue-storefront/core'

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

export default function RedisCache (options) {
const { version, ...redisConfig } = options;

const client = new Redis(redisConfig);
const fallbackVersion = crypto.randomBytes(15).toString('hex')

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

if (!version) {
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.');
}

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

if (cachedResponse) {
Expand Down