mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
Moved cache storage initialization
refs https://github.com/TryGhost/Toolbox/issues/364 - Passing "cache" through constructor did not work out because cache setting is still dependent upon on the model layer (gets called before it has a chance to initialize during db migrations) - To remove the initialization dependency blockers were: "defaults" method in the post model - the value resolved to "undefined" anyway during the fixture insertion validate-password module - checks the password against "undefined" during fixture initialization - Passing the cache through "init" method works too, but is not as clear as with constructor DI pattern.
This commit is contained in:
parent
e9bfc4ef01
commit
af0014917b
4 changed files with 13 additions and 10 deletions
|
@ -67,7 +67,7 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
async init() {
|
async init() {
|
||||||
const settingsCollection = await models.Settings.populateDefaults();
|
const settingsCollection = await models.Settings.populateDefaults();
|
||||||
SettingsCache.init(events, settingsCollection, this.getCalculatedFields());
|
SettingsCache.init(events, settingsCollection, this.getCalculatedFields(), {});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,11 +14,11 @@ const _ = require('lodash');
|
||||||
class CacheManager {
|
class CacheManager {
|
||||||
/**
|
/**
|
||||||
* @prop {Object} options
|
* @prop {Object} options
|
||||||
* @prop {{}} options.cache - object of objects. Holds cached settings, keyed by setting.key, contains the JSON version of the model
|
|
||||||
* @prop {Object} options.publicSettings - key/value pairs of settings which are publicly accessible
|
* @prop {Object} options.publicSettings - key/value pairs of settings which are publicly accessible
|
||||||
*/
|
*/
|
||||||
constructor({cache, publicSettings}) {
|
constructor({publicSettings}) {
|
||||||
this.settingsCache = cache;
|
// settingsCache holds cached settings, keyed by setting.key, contains the JSON version of the model
|
||||||
|
this.settingsCache;
|
||||||
this.publicSettings = publicSettings;
|
this.publicSettings = publicSettings;
|
||||||
this.calculatedFields = [];
|
this.calculatedFields = [];
|
||||||
|
|
||||||
|
@ -47,7 +47,10 @@ class CacheManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
_doGet(key, options) {
|
_doGet(key, options) {
|
||||||
if (!this.settingsCache[key]) {
|
// NOTE: "!this.settingsCache" is for when setting's cache is used
|
||||||
|
// before it had a chance to initialize. Should be fixed when
|
||||||
|
// it is decoupled from the model layer
|
||||||
|
if (!this.settingsCache || !this.settingsCache[key]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,9 +146,11 @@ class CacheManager {
|
||||||
* @param {EventEmitter} events
|
* @param {EventEmitter} events
|
||||||
* @param {Bookshelf.Collection<Settings>} settingsCollection
|
* @param {Bookshelf.Collection<Settings>} settingsCollection
|
||||||
* @param {Array} calculatedFields
|
* @param {Array} calculatedFields
|
||||||
|
* @param {Object} cacheStore - cache storage instance
|
||||||
* @return {object}
|
* @return {object}
|
||||||
*/
|
*/
|
||||||
init(events, settingsCollection, calculatedFields) {
|
init(events, settingsCollection, calculatedFields, cacheStore) {
|
||||||
|
this.settingsCache = cacheStore;
|
||||||
// First, reset the cache and
|
// First, reset the cache and
|
||||||
this.reset(events);
|
this.reset(events);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
const CacheManager = require('./cache');
|
const CacheManager = require('./cache');
|
||||||
const publicSettings = require('./public');
|
const publicSettings = require('./public');
|
||||||
const cache = {};
|
|
||||||
|
|
||||||
const cacheManager = new CacheManager({cache, publicSettings});
|
const cacheManager = new CacheManager({publicSettings});
|
||||||
|
|
||||||
module.exports = cacheManager;
|
module.exports = cacheManager;
|
||||||
|
|
|
@ -14,10 +14,9 @@ describe('UNIT: settings cache', function () {
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
cache = new CacheManager({
|
cache = new CacheManager({
|
||||||
cache: {},
|
|
||||||
publicSettings
|
publicSettings
|
||||||
});
|
});
|
||||||
cache.init(events, {}, []);
|
cache.init(events, {}, [], {});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue