fix(chore): contentExpire not work
This commit is contained in:
parent
aadc66ba31
commit
c4cd0ab495
|
|
@ -268,7 +268,7 @@ Use environment variables is recommended to avoid conflicts during upgrade.
|
|||
|
||||
`CACHE_EXPIRE`: route cache expiry time in seconds, default to `5 * 60`
|
||||
|
||||
`CACHE_CONTENT_EXPIRE`: content cache expiry time in seconds, default to `24 * 60 * 60`
|
||||
`CACHE_CONTENT_EXPIRE`: content cache expiry time in seconds, it will be recalculated when it is accessed, default to `1 * 60 * 60`
|
||||
|
||||
`LISTEN_INADDR_ANY`: open up for external access, default to `1`
|
||||
|
||||
|
|
|
|||
|
|
@ -313,7 +313,7 @@ $ docker run -d --name rsshub -p 1200:1200 rsshub:arm32v7
|
|||
|
||||
`CACHE_EXPIRE`: 路由缓存过期时间, 单位为秒, 默认 `5 * 60`
|
||||
|
||||
`CACHE_CONTENT_EXPIRE`: 内容缓存过期时间,单位为秒, 默认 `24 * 60 * 60`
|
||||
`CACHE_CONTENT_EXPIRE`: 内容缓存过期时间,每次访问会重新计算过期时间,单位为秒, 默认 `1 * 60 * 60`
|
||||
|
||||
`LISTEN_INADDR_ANY`: 是否允许公网连接, 默认 `1`
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ module.exports = {
|
|||
cache: {
|
||||
type: process.env.CACHE_TYPE || 'memory', // 缓存类型,支持 'memory' 和 'redis',设为空可以禁止缓存
|
||||
routeExpire: parseInt(process.env.CACHE_EXPIRE) || 5 * 60, // 路由缓存时间,单位为秒
|
||||
contentExpire: parseInt(process.env.CACHE_CONTENT_EXPIRE) || 24 * 60 * 60, // 不变内容缓存时间,单位为秒
|
||||
contentExpire: parseInt(process.env.CACHE_CONTENT_EXPIRE) || 1 * 60 * 60, // 不变内容缓存时间,单位为秒
|
||||
},
|
||||
ua: process.env.UA || 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
|
||||
listenInaddrAny: parseInt(process.env.LISTEN_INADDR_ANY) || 1, // 是否允许公网连接,取值 0 1
|
||||
|
|
|
|||
|
|
@ -38,13 +38,13 @@ module.exports = function(app, options = {}) {
|
|||
if (key) {
|
||||
let value = await redisClient.get(key);
|
||||
if (value) {
|
||||
await redisClient.expire(key, config.cache.routeExpire);
|
||||
await redisClient.expire(key, config.cache.contentExpire);
|
||||
value = value + '';
|
||||
}
|
||||
return value;
|
||||
}
|
||||
},
|
||||
set: async function(key, value, maxAge = config.cache.routeExpire) {
|
||||
set: async function(key, value, maxAge = config.cache.contentExpire) {
|
||||
if (await redisClient.exists(key)) {
|
||||
logger.warn(`repeated key: ${key}, ${value}`);
|
||||
return;
|
||||
|
|
@ -89,7 +89,7 @@ module.exports = function(app, options = {}) {
|
|||
return value;
|
||||
}
|
||||
},
|
||||
set: (key, value, maxAge = config.cache.routeExpire) => {
|
||||
set: (key, value, maxAge = config.cache.contentExpire) => {
|
||||
if (!value || value === 'undefined') {
|
||||
value = '';
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ module.exports = function(app, options = {}) {
|
|||
};
|
||||
}
|
||||
|
||||
app.context.cache.tryGet = async function(key, getValueFunc, maxAge = config.cache.routeExpire) {
|
||||
app.context.cache.tryGet = async function(key, getValueFunc, maxAge = config.cache.contentExpire) {
|
||||
let v = await this.get(key);
|
||||
if (!v) {
|
||||
v = await getValueFunc();
|
||||
|
|
|
|||
|
|
@ -1,19 +1,5 @@
|
|||
const axios = require('../../../utils/axios');
|
||||
|
||||
/** @type { (timezoneOffset: number) => Date } */
|
||||
const tomorrowMidnight = (timezoneOffset) => {
|
||||
const result = new Date(Date.now());
|
||||
const localHour = result.getHours() + timezoneOffset;
|
||||
if (localHour < 0) {
|
||||
result.setUTCHours(-timezoneOffset, 0, 0, 0);
|
||||
} else if (localHour < 24) {
|
||||
result.setUTCHours(24 - timezoneOffset, 0, 0, 0);
|
||||
} else {
|
||||
result.setUTCHours(48 - timezoneOffset, 0, 0, 0);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const bgmCalendarUrl = 'https://api.bgm.tv/calendar';
|
||||
const bgmDataUrl = 'https://cdn.jsdelivr.net/npm/bangumi-data/dist/data.json';
|
||||
|
|
@ -47,7 +33,7 @@ module.exports = async (ctx) => {
|
|||
data.items = items;
|
||||
}
|
||||
|
||||
ctx.cache.set(url[i], JSON.stringify(data), tomorrowMidnight(8).getTime() - Date.now());
|
||||
ctx.cache.set(url[i], JSON.stringify(data));
|
||||
return Promise.resolve(data);
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ module.exports = async (ctx) => {
|
|||
// 格式化日期
|
||||
pubDate: date(dateStr),
|
||||
};
|
||||
ctx.cache.set(absoluteUrl, JSON.stringify(item), 24 * 60 * 60);
|
||||
ctx.cache.set(absoluteUrl, JSON.stringify(item));
|
||||
|
||||
return Promise.resolve(item);
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue