Browse Source

fix: refresh TTL on cache set

pull/7596/head
mertmit 9 months ago
parent
commit
4a543bbb1a
  1. 13
      packages/nocodb/src/cache/CacheMgr.ts

13
packages/nocodb/src/cache/CacheMgr.ts vendored

@ -150,12 +150,17 @@ export default abstract class CacheMgr {
}); });
} }
return this.client.set( return this.client
.set(
key, key,
JSON.stringify(value, this.getCircularReplacer()), JSON.stringify(value, this.getCircularReplacer()),
'EX', 'EX',
NC_REDIS_TTL, NC_REDIS_TTL,
); )
.then(async () => {
await this.refreshTTL(key, timestamp);
return true;
});
} else { } else {
log(`${this.context}::set: value is empty for ${key}. Skipping ...`); log(`${this.context}::set: value is empty for ${key}. Skipping ...`);
return Promise.resolve(true); return Promise.resolve(true);
@ -534,6 +539,7 @@ export default abstract class CacheMgr {
try { try {
const o = JSON.parse(v); const o = JSON.parse(v);
if (typeof o === 'object') { if (typeof o === 'object') {
if (o.timestamp !== timestamp) {
o.timestamp = timestamp; o.timestamp = timestamp;
pipeline.set( pipeline.set(
key, key,
@ -542,6 +548,7 @@ export default abstract class CacheMgr {
NC_REDIS_TTL, NC_REDIS_TTL,
); );
} }
}
} catch (e) { } catch (e) {
logger.error( logger.error(
`${this.context}::refreshTTL: Bad value stored for key ${key} : ${v}`, `${this.context}::refreshTTL: Bad value stored for key ${key} : ${v}`,
@ -560,6 +567,7 @@ export default abstract class CacheMgr {
await this.refreshTTL(parent, timestamp); await this.refreshTTL(parent, timestamp);
} }
} else { } else {
if (rawValue.timestamp !== timestamp) {
rawValue.timestamp = timestamp; rawValue.timestamp = timestamp;
await this.client.set( await this.client.set(
key, key,
@ -571,6 +579,7 @@ export default abstract class CacheMgr {
} }
} }
} }
}
async destroy(): Promise<boolean> { async destroy(): Promise<boolean> {
log('${this.context}::destroy: destroy redis'); log('${this.context}::destroy: destroy redis');

Loading…
Cancel
Save