mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-15 18:30:53 +08:00
app: expose cache function to koa context
This commit is contained in:
@@ -21,6 +21,11 @@ module.exports = function(options = {}) {
|
|||||||
max: maxLength,
|
max: maxLength,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
options.app.context.cache = {
|
||||||
|
get: (key) => memoryCache.get(key),
|
||||||
|
set: (key, value, maxAge) => memoryCache.set(key, value, maxAge),
|
||||||
|
};
|
||||||
|
|
||||||
return async function cache(ctx, next) {
|
return async function cache(ctx, next) {
|
||||||
const { url, path } = ctx.request;
|
const { url, path } = ctx.request;
|
||||||
const resolvedPrefix = typeof prefix === 'function' ? prefix.call(ctx, ctx) : prefix;
|
const resolvedPrefix = typeof prefix === 'function' ? prefix.call(ctx, ctx) : prefix;
|
||||||
|
|||||||
@@ -39,6 +39,11 @@ module.exports = function(options = {}) {
|
|||||||
onconnect();
|
onconnect();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
options.app.context.cache = {
|
||||||
|
get: async (key) => await redisClient.get(key),
|
||||||
|
set: async (key, value, maxAge) => await redisClient.setex(key, maxAge, value),
|
||||||
|
};
|
||||||
|
|
||||||
return async function cache(ctx, next) {
|
return async function cache(ctx, next) {
|
||||||
const { url, path } = ctx.request;
|
const { url, path } = ctx.request;
|
||||||
const resolvedPrefix = typeof prefix === 'function' ? prefix.call(ctx, ctx) : prefix;
|
const resolvedPrefix = typeof prefix === 'function' ? prefix.call(ctx, ctx) : prefix;
|
||||||
|
|||||||
Reference in New Issue
Block a user