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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache instance fix #2359

Merged
merged 3 commits into from
Feb 4, 2019
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `store/lib/search` has been moved to `core/lib/search` (#2225)
- `store/lib/multistore` has been moved to `core/lib/multistore` (#2224)
- After checkout create logged-in cart for logged-in users if using order Direct Backend Sync - @grimasod (#2302)
- Output cache clearing supports versioning - @igloczek (#2333 + #2359)

## [1.7.3] - 2019.01.31
### Fixed
Expand Down
15 changes: 7 additions & 8 deletions core/scripts/cache.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { Logger } from '@vue-storefront/core/lib/logger'

const program = require('commander')
const config = require('config')
const cache = require('./utils/cache-instance')

program
.command('clear')
.option('-t|--tag <tag>', 'tag name, available tags: ' + config.server.availableCacheTags.join(', '), '*')
.action((cmd) => { // TODO: add parallel processing
if (!cmd.tag) {
Logger.error('error: tag must be specified')()
console.error('error: tag must be specified')
process.exit(1)
} else {
Logger.log(`Clear cache request for [${cmd.tag}]`)()
console.log(`Clear cache request for [${cmd.tag}]`)
let tags = []
if (cmd.tag === '*') {
tags = config.server.availableCacheTags
Expand All @@ -24,17 +23,17 @@ program
return tag.indexOf(t) === 0
})) {
subPromises.push(cache.invalidate(tag).then(() => {
Logger.log(`Tags invalidated successfully for [${tag}]`)()
console.log(`Tags invalidated successfully for [${tag}]`)
}))
} else {
Logger.error(`Invalid tag name ${tag}`)()
console.error(`Invalid tag name ${tag}`)
}
})
Promise.all(subPromises).then(r => {
Logger.log(`All tags invalidated successfully [${cmd.tag}]`)()
console.log(`All tags invalidated successfully [${cmd.tag}]`)
process.exit(0)
}).catch(error => {
Logger.error(error)()
console.error(error)
})
}
})
Expand Down
13 changes: 6 additions & 7 deletions core/scripts/utils/cache-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ const fs = require('fs')
const path = require('path')
const TagCache = require('redis-tag-cache').default
const config = require('config')
let cache = false

module.exports = () => {
if (config.server.useOutputCache) {
return false
}

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

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

return new TagCache({
cache = new TagCache({
redis: redisConfig,
defaultTimeout: config.server.outputCacheDefaultTtl
})
}

module.exports = cache