Node.js based forum software built for the modern web
refactor: add names to caches, add max to request cache
Barış Soner Uşaklıa08551a5e168
diff --git a/src/activitypub/index.js b/src/activitypub/index.jsindex 78cb3f26f6..ef69d0bdf4 100644--- a/src/activitypub/index.js+++ b/src/activitypub/index.js@@ -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});diff --git a/src/cache/lru.js b/src/cache/lru.jsindex 094d3a3e93..2d46e5a5fe 100644--- a/src/cache/lru.js+++ b/src/cache/lru.js@@ -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;diff --git a/src/cache/ttl.js b/src/cache/ttl.jsindex 8647d0b9ac..fdc134be81 100644--- a/src/cache/ttl.js+++ b/src/cache/ttl.js@@ -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;diff --git a/src/middleware/index.js b/src/middleware/index.jsindex 417d8309bc..67d8e2faa0 100644--- a/src/middleware/index.js+++ b/src/middleware/index.js@@ -23,6 +23,7 @@ const controllers = {};const delayCache = cacheCreate({+ name: 'delay-middleware',ttl: 1000 * 60,max: 200,});diff --git a/src/notifications.js b/src/notifications.jsindex df7cf51fb4..4e6e7873f3 100644--- a/src/notifications.js+++ b/src/notifications.js@@ -22,6 +22,7 @@ const Notifications = module.exports;// ttlcache for email-only chat notificationsconst notificationCache = ttlCache({+ name: 'notification-email-cache',max: 1000,ttl: (meta.config.notificationSendDelay || 60) * 1000,noDisposeOnSet: true,diff --git a/src/request.js b/src/request.jsindex ce5e95d5bb..713c3dd6ac 100644--- a/src/request.js+++ b/src/request.js@@ -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();