mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 18:16:17 +01:00
refactor: add names to caches, add max to request cache
This commit is contained in:
@@ -20,14 +20,17 @@ const pubsub = require('../pubsub');
|
||||
const analytics = require('../analytics');
|
||||
|
||||
const requestCache = ttl({
|
||||
name: 'ap-request-cache',
|
||||
max: 5000,
|
||||
ttl: 1000 * 60 * 5, // 5 minutes
|
||||
});
|
||||
const probeCache = ttl({
|
||||
name: 'ap-probe-cache',
|
||||
max: 500,
|
||||
ttl: 1000 * 60 * 60, // 1 hour
|
||||
});
|
||||
const probeRateLimit = ttl({
|
||||
name: 'ap-probe-rate-limit-cache',
|
||||
ttl: 1000 * 3, // 3 seconds
|
||||
});
|
||||
|
||||
|
||||
3
src/cache/lru.js
vendored
3
src/cache/lru.js
vendored
@@ -31,6 +31,9 @@ module.exports = function (opts) {
|
||||
});
|
||||
|
||||
const lruCache = new LRUCache(opts);
|
||||
if (!opts.name) {
|
||||
winston.warn(`[cache/init] ${chalk.white.bgRed.bold('WARNING')} The cache name is not set. This will be required in the future.\n ${new Error('t').stack} `);
|
||||
}
|
||||
|
||||
const cache = {};
|
||||
cache.name = opts.name;
|
||||
|
||||
5
src/cache/ttl.js
vendored
5
src/cache/ttl.js
vendored
@@ -3,10 +3,15 @@
|
||||
module.exports = function (opts) {
|
||||
const TTLCache = require('@isaacs/ttlcache');
|
||||
const os = require('os');
|
||||
const winston = require('winston');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const pubsub = require('../pubsub');
|
||||
|
||||
const ttlCache = new TTLCache(opts);
|
||||
if (!opts.name) {
|
||||
winston.warn(`[cache/init] ${chalk.white.bgRed.bold('WARNING')} The cache name is not set. This will be required in the future.\n ${new Error('t').stack} `);
|
||||
}
|
||||
|
||||
const cache = {};
|
||||
cache.name = opts.name;
|
||||
|
||||
@@ -23,6 +23,7 @@ const controllers = {
|
||||
};
|
||||
|
||||
const delayCache = cacheCreate({
|
||||
name: 'delay-middleware',
|
||||
ttl: 1000 * 60,
|
||||
max: 200,
|
||||
});
|
||||
|
||||
@@ -22,6 +22,7 @@ const Notifications = module.exports;
|
||||
|
||||
// ttlcache for email-only chat notifications
|
||||
const notificationCache = ttlCache({
|
||||
name: 'notification-email-cache',
|
||||
max: 1000,
|
||||
ttl: (meta.config.notificationSendDelay || 60) * 1000,
|
||||
noDisposeOnSet: true,
|
||||
|
||||
@@ -12,6 +12,8 @@ const { version } = require('../package.json');
|
||||
const plugins = require('./plugins');
|
||||
const ttl = require('./cache/ttl');
|
||||
const checkCache = ttl({
|
||||
name: 'request-check',
|
||||
max: 1000,
|
||||
ttl: 1000 * 60 * 60, // 1 hour
|
||||
});
|
||||
let allowList = new Set();
|
||||
|
||||
Reference in New Issue
Block a user