mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 15:47:48 +08:00
* chore(deps): bump lru-cache from 8.0.5 to 9.1.1 Bumps [lru-cache](https://github.com/isaacs/node-lru-cache) from 8.0.5 to 9.1.1. - [Release notes](https://github.com/isaacs/node-lru-cache/releases) - [Changelog](https://github.com/isaacs/node-lru-cache/blob/main/CHANGELOG.md) - [Commits](https://github.com/isaacs/node-lru-cache/compare/v8.0.5...v9.1.1) --- updated-dependencies: - dependency-name: lru-cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix: use named export --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
37 lines
959 B
JavaScript
37 lines
959 B
JavaScript
const { LRUCache } = require('lru-cache');
|
|
const config = require('@/config').value;
|
|
|
|
const status = { available: false };
|
|
|
|
const memoryCache = new LRUCache({
|
|
ttl: config.cache.routeExpire * 1000,
|
|
max: config.memory.max,
|
|
});
|
|
|
|
status.available = true;
|
|
|
|
module.exports = {
|
|
get: (key, refresh = true) => {
|
|
if (key && status.available) {
|
|
let value = memoryCache.get(key, { updateAgeOnGet: refresh });
|
|
if (value) {
|
|
value = value + '';
|
|
}
|
|
return value;
|
|
}
|
|
},
|
|
set: (key, value, maxAge = config.cache.contentExpire) => {
|
|
if (!value || value === 'undefined') {
|
|
value = '';
|
|
}
|
|
if (typeof value === 'object') {
|
|
value = JSON.stringify(value);
|
|
}
|
|
if (key && status.available) {
|
|
return memoryCache.set(key, value, { ttl: maxAge * 1000 });
|
|
}
|
|
},
|
|
clients: { memoryCache },
|
|
status,
|
|
};
|