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
This commit is contained in:
Kevin Ansfield 2021-09-28 15:46:32 +01:00
parent 372e89f8ce
commit 2bb5a9cb6e

View File

@ -12,8 +12,16 @@ module.exports = class CustomThemeSettingsCache {
}
populate(settings) {
this.clear();
settings.forEach((setting) => {
this.content[setting.key] = setting.value;
});
}
clear() {
for (const key in this.content) {
delete this.content[key];
}
}
};