Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output cache versioning #2309

Merged
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ config/local.json
var
build/config.json
core/build/config.json
core/build/cache-version.json
theme.js
desktop.ini
src/themes/catalog/resource/i18n.json
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- cache key used to store output chache in redis

## [1.7.2] - 2019.01.28
### Fixed
- clear search filters on mobile - @patzick (#2282)
Expand Down
12 changes: 12 additions & 0 deletions core/build/webpack.server.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ const merge = require('webpack-merge')
const base = require('./webpack.base.config')
const VueSSRPlugin = require('vue-ssr-webpack-plugin')

// when output cache is enabled generate cache version key
const config = require('config')
const fs = require('fs')
const path = require('path')
const uuid = require('uuid/v4')
if (config.server.useOutputCache) {
fs.writeFileSync(
path.join(__dirname, 'cache-version.json'),
JSON.stringify(uuid())
)
}

module.exports = merge(base, {
mode: 'development',
target: 'node',
Expand Down
1 change: 1 addition & 0 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"lru-cache": "^4.0.1",
"redis-tag-cache": "^1.2.1",
"remove-accents": "^0.4.2",
"uuid": "^3.3.2",
"vue": "^2.5.17",
"vue-carousel": "^0.6.9",
"vue-i18n": "^8.0.0",
Expand Down
12 changes: 9 additions & 3 deletions core/scripts/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,28 @@ let config = require('config')
const TagCache = require('redis-tag-cache').default
const utils = require('./server/utils')
const compile = require('lodash.template')

const compileOptions = {
escape: /{{([^{][\s\S]+?[^}])}}/g,
interpolate: /{{{([\s\S]+?)}}}/g
}

const isProd = process.env.NODE_ENV === 'production'
process.noDeprecation = true

const app = express()

let cache
if (config.server.useOutputCache) {
const cacheKey = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'build', 'cache-version.json')) || '')
const redisConfig = Object.assign(config.redis, { keyPrefix: cacheKey })

cache = new TagCache({
redis: config.redis,
defaultTimeout: config.server.outputCacheDefaultTtl // Expire records after a day (even if they weren't invalidated)
redis: redisConfig,
defaultTimeout: config.server.outputCacheDefaultTtl
})
console.log('Redis cache set', config.redis)

console.log('Redis cache set', redisConfig)
}

const templatesCache = {}
Expand Down