refactor: add names to caches, add max to request cache

This commit is contained in:
Barış Soner Uşaklı
2025-07-16 17:42:23 -04:00
parent 1ad97ac194
commit a08551a5e1
6 changed files with 15 additions and 0 deletions

View File

@@ -20,14 +20,17 @@ const pubsub = require('../pubsub');
const analytics = require('../analytics'); const analytics = require('../analytics');
const requestCache = ttl({ const requestCache = ttl({
name: 'ap-request-cache',
max: 5000, max: 5000,
ttl: 1000 * 60 * 5, // 5 minutes ttl: 1000 * 60 * 5, // 5 minutes
}); });
const probeCache = ttl({ const probeCache = ttl({
name: 'ap-probe-cache',
max: 500, max: 500,
ttl: 1000 * 60 * 60, // 1 hour ttl: 1000 * 60 * 60, // 1 hour
}); });
const probeRateLimit = ttl({ const probeRateLimit = ttl({
name: 'ap-probe-rate-limit-cache',
ttl: 1000 * 3, // 3 seconds ttl: 1000 * 3, // 3 seconds
}); });

3
src/cache/lru.js vendored
View File

@@ -31,6 +31,9 @@ module.exports = function (opts) {
}); });
const lruCache = new LRUCache(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 = {}; const cache = {};
cache.name = opts.name; cache.name = opts.name;

5
src/cache/ttl.js vendored
View File

@@ -3,10 +3,15 @@
module.exports = function (opts) { module.exports = function (opts) {
const TTLCache = require('@isaacs/ttlcache'); const TTLCache = require('@isaacs/ttlcache');
const os = require('os'); const os = require('os');
const winston = require('winston');
const chalk = require('chalk');
const pubsub = require('../pubsub'); const pubsub = require('../pubsub');
const ttlCache = new TTLCache(opts); 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 = {}; const cache = {};
cache.name = opts.name; cache.name = opts.name;

View File

@@ -23,6 +23,7 @@ const controllers = {
}; };
const delayCache = cacheCreate({ const delayCache = cacheCreate({
name: 'delay-middleware',
ttl: 1000 * 60, ttl: 1000 * 60,
max: 200, max: 200,
}); });

View File

@@ -22,6 +22,7 @@ const Notifications = module.exports;
// ttlcache for email-only chat notifications // ttlcache for email-only chat notifications
const notificationCache = ttlCache({ const notificationCache = ttlCache({
name: 'notification-email-cache',
max: 1000, max: 1000,
ttl: (meta.config.notificationSendDelay || 60) * 1000, ttl: (meta.config.notificationSendDelay || 60) * 1000,
noDisposeOnSet: true, noDisposeOnSet: true,

View File

@@ -12,6 +12,8 @@ const { version } = require('../package.json');
const plugins = require('./plugins'); const plugins = require('./plugins');
const ttl = require('./cache/ttl'); const ttl = require('./cache/ttl');
const checkCache = ttl({ const checkCache = ttl({
name: 'request-check',
max: 1000,
ttl: 1000 * 60 * 60, // 1 hour ttl: 1000 * 60 * 60, // 1 hour
}); });
let allowList = new Set(); let allowList = new Set();