mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: race condition that results in 2x localReset call the same process
This commit is contained in:
12
src/cache/lru.js
vendored
12
src/cache/lru.js
vendored
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
module.exports = function (opts) {
|
module.exports = function (opts) {
|
||||||
const { LRUCache } = require('lru-cache');
|
const { LRUCache } = require('lru-cache');
|
||||||
|
const os = require('os');
|
||||||
|
|
||||||
const pubsub = require('../pubsub');
|
const pubsub = require('../pubsub');
|
||||||
|
|
||||||
// lru-cache@7 deprecations
|
// lru-cache@7 deprecations
|
||||||
@@ -91,7 +93,9 @@ module.exports = function (opts) {
|
|||||||
cache.delete = cache.del;
|
cache.delete = cache.del;
|
||||||
|
|
||||||
cache.reset = function () {
|
cache.reset = function () {
|
||||||
pubsub.publish(`${cache.name}:lruCache:reset`);
|
pubsub.publish(`${cache.name}:lruCache:reset`, {
|
||||||
|
id: `${os.hostname()}:${process.pid}`,
|
||||||
|
});
|
||||||
localReset();
|
localReset();
|
||||||
};
|
};
|
||||||
cache.clear = cache.reset;
|
cache.clear = cache.reset;
|
||||||
@@ -102,8 +106,10 @@ module.exports = function (opts) {
|
|||||||
cache.misses = 0;
|
cache.misses = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pubsub.on(`${cache.name}:lruCache:reset`, () => {
|
pubsub.on(`${cache.name}:lruCache:reset`, ({ id }) => {
|
||||||
localReset();
|
if (id !== `${os.hostname()}:${process.pid}`) {
|
||||||
|
localReset();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
pubsub.on(`${cache.name}:lruCache:del`, (keys) => {
|
pubsub.on(`${cache.name}:lruCache:del`, (keys) => {
|
||||||
|
|||||||
12
src/cache/ttl.js
vendored
12
src/cache/ttl.js
vendored
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
module.exports = function (opts) {
|
module.exports = function (opts) {
|
||||||
const TTLCache = require('@isaacs/ttlcache');
|
const TTLCache = require('@isaacs/ttlcache');
|
||||||
|
const os = require('os');
|
||||||
|
|
||||||
const pubsub = require('../pubsub');
|
const pubsub = require('../pubsub');
|
||||||
|
|
||||||
const ttlCache = new TTLCache(opts);
|
const ttlCache = new TTLCache(opts);
|
||||||
@@ -72,7 +74,9 @@ module.exports = function (opts) {
|
|||||||
cache.delete = cache.del;
|
cache.delete = cache.del;
|
||||||
|
|
||||||
cache.reset = function () {
|
cache.reset = function () {
|
||||||
pubsub.publish(`${cache.name}:ttlCache:reset`);
|
pubsub.publish(`${cache.name}:ttlCache:reset`, {
|
||||||
|
id: `${os.hostname()}:${process.pid}`,
|
||||||
|
});
|
||||||
localReset();
|
localReset();
|
||||||
};
|
};
|
||||||
cache.clear = cache.reset;
|
cache.clear = cache.reset;
|
||||||
@@ -83,8 +87,10 @@ module.exports = function (opts) {
|
|||||||
cache.misses = 0;
|
cache.misses = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pubsub.on(`${cache.name}:ttlCache:reset`, () => {
|
pubsub.on(`${cache.name}:ttlCache:reset`, ({ id }) => {
|
||||||
localReset();
|
if (id !== `${os.hostname()}:${process.pid}`) {
|
||||||
|
localReset();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
pubsub.on(`${cache.name}:ttlCache:del`, (keys) => {
|
pubsub.on(`${cache.name}:ttlCache:del`, (keys) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user