Ghost/ghost/custom-theme-settings-service/lib/cache.js
Kevin Ansfield 2bb5a9cb6e Fixed cache.populate() leaving behind old settings
refs https://github.com/TryGhost/Team/issues/1070

- if the cache is repopulated, keys that already existed in the cache but that don't exist in the new group of settings were left in the cache
- added a `.clear()` method that removes all items from the cache and call it when populating so the cache only contains what it was last populated with
  - deletes properties on the internal content object so that references aren't lost
2021-09-28 15:50:46 +01:00

28 lines
502 B
JavaScript

module.exports = class CustomThemeSettingsCache {
constructor() {
this.content = new Object();
}
get(key) {
return this.content[key].value;
}
getAll() {
return this.content;
}
populate(settings) {
this.clear();
settings.forEach((setting) => {
this.content[setting.key] = setting.value;
});
}
clear() {
for (const key in this.content) {
delete this.content[key];
}
}
};