Greetings everyone! Recently I noticed that my fallback caching to local cache stopped working as intended.
The issue in short is extremely similar to https://github.com/nestjs/nest/issues/11145
If I set my key and instantly retrieve it using get It works, but when I’m trying to retrieve my keys elsewhere (after the fact they have been set) they are retrieved as “undefined”
This works:
async setLocalCache() {
try {
const myObj = {
myData: data,
timestamp: Date.now(),
};
const stringData = JSON.stringify(myObj);
this.cacheManager.set('MY_KEY_NAME', stringData, 14410000);
const retrievedData = await this.cacheManager.get('MY_KEY_NAME');
console.log(JSON.parse(retreivedData))
} catch (error) {
this.logger.error(error);
}
}
This doesn’t work:
async setLocalCache() {
try {
const myObj = {
myData: data,
timestamp: Date.now(),
};
const stringData = JSON.stringify(myObj);
this.cacheManager.set('MY_KEY_NAME', stringData, 14410000);
} catch (error) {
this.logger.error(error);
}
}
async getLocalCache(keyName: string) {
try {
const localRate = await this.cacheManager.get<string>(keyName);
return localRate ? JSON.parse(localRate) : null;
} catch (error) {
this.logger.error(error);
}
}
It fails when I am trying to retrieve values from cache out of the scope of the setting of the value.
First post here, hopefully I put my issue on the paper humanly!