mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-14 17:19:37 +08:00
Update tryGet() and use default parameters
This commit is contained in:
@@ -94,11 +94,11 @@ if (config.cacheType === 'memory') {
|
|||||||
set: () => null,
|
set: () => null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
app.context.cache.tryGet = async function(key, getValueFunc, maxAge = 24 * 60 * 60) {
|
app.context.cache.tryGet = async function(key, getValueFunc, maxAge = 24 * 60 * 60, persistent = false) {
|
||||||
let v = await this.get(key);
|
let v = await this.get(key, persistent);
|
||||||
if (!v) {
|
if (!v) {
|
||||||
v = await getValueFunc();
|
v = await getValueFunc();
|
||||||
this.set(key, v, maxAge);
|
this.set(key, v, maxAge, persistent);
|
||||||
} else {
|
} else {
|
||||||
let parsed;
|
let parsed;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ module.exports = function(options = {}) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
options.app.context.cache = {
|
options.app.context.cache = {
|
||||||
get: (key, persistent) => {
|
get: (key, persistent = false) => {
|
||||||
if (key) {
|
if (key) {
|
||||||
if (persistent) {
|
if (persistent) {
|
||||||
return persistentCache.get(key);
|
return persistentCache.get(key);
|
||||||
@@ -35,7 +35,7 @@ module.exports = function(options = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
set: (key, value, maxAge, persistent) => {
|
set: (key, value, maxAge, persistent = false) => {
|
||||||
if (!value || value === 'undefined') {
|
if (!value || value === 'undefined') {
|
||||||
value = '';
|
value = '';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,13 +42,13 @@ module.exports = function(options = {}) {
|
|||||||
|
|
||||||
options.app.context.cache = {
|
options.app.context.cache = {
|
||||||
/* eslint-disable no-unused-vars */
|
/* eslint-disable no-unused-vars */
|
||||||
get: async (key, persistent) => {
|
get: async (key, persistent = false) => {
|
||||||
/* eslint-enable no-unused-vars */
|
/* eslint-enable no-unused-vars */
|
||||||
if (key) {
|
if (key) {
|
||||||
return await redisClient.get(key);
|
return await redisClient.get(key);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
set: async (key, value, maxAge, persistent) => {
|
set: async (key, value, maxAge, persistent = false) => {
|
||||||
if (!value || value === 'undefined') {
|
if (!value || value === 'undefined') {
|
||||||
value = '';
|
value = '';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user