diff --git a/CHANGELOG.md b/CHANGELOG.md index 30ef480329..b33746c6fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/core/scripts/cache.js b/core/scripts/cache.js index 6d979adf48..4038647ad9 100644 --- a/core/scripts/cache.js +++ b/core/scripts/cache.js @@ -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 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 @@ -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) }) } }) diff --git a/core/scripts/utils/cache-instance.js b/core/scripts/utils/cache-instance.js index 8987b23880..2dd09e26d7 100644 --- a/core/scripts/utils/cache-instance.js +++ b/core/scripts/utils/cache-instance.js @@ -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