refactor(core): unified memory cache (#9395)

Signed-off-by: Rongrong <15956627+Rongronggg9@users.noreply.github.com>
This commit is contained in:
Rongrong
2022-03-28 22:55:29 +08:00
committed by GitHub
parent cd151f45ab
commit 501dff59d0
5 changed files with 11 additions and 17 deletions

View File

@@ -27,10 +27,10 @@ if (config.cache.type === 'redis') {
globalCache.set = cacheModule.set;
} else if (config.cache.type === 'memory') {
cacheModule = require('./memory');
const { pageCache } = cacheModule.clients;
const { memoryCache } = cacheModule.clients;
globalCache.get = (key) => {
if (key && cacheModule.status.available) {
return pageCache.get(key);
return memoryCache.get(key, { updateAgeOnGet: false });
}
};
globalCache.set = (key, value, maxAge) => {
@@ -41,7 +41,7 @@ if (config.cache.type === 'redis') {
value = JSON.stringify(value);
}
if (key) {
return pageCache.set(key, value, { ttl: maxAge * 1000 });
return memoryCache.set(key, value, { ttl: maxAge * 1000 });
}
};
} else {