let cache: {
[key: string]: any;
} = null;
ConfigModel.find({}).then((config) => {
cache = Object.fromEntries(config.map((c) => [c.name, c.value]));
});
export async function populate() {
const config = await ConfigModel.find({});
cache = Object.fromEntries(config.map((c) => [c.name, c.value]));
}
setInterval(() => {
ConfigModel.find({}).then((config) => {
cache = Object.fromEntries(config.map((c) => [c.name, c.value]));
});
}, 60000);
export function getConfig(value: string) {
return cache[value];
}
Hi, i’m using this caching system for a config collection I have on mongoDB, but I’d like to use a post action with the schema, to live edit the cache when editing a property using Compass, currently, I have to wait 1min for the changes to be taken in count, I tried to use .post(‘updateOne’), but I got nothing.