Skip to content

Commit 975b177

Browse files
committed
Fix PM2 cluster sync - use cache.cache.size instead of cache.length()
All tests passing
1 parent 39a7ea7 commit 975b177

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

cache/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ const originalInvalidate = cache.invalidate.bind(cache)
651651
const originalClear = cache.clear.bind(cache)
652652

653653
// Wrap set() to broadcast to other instances
654-
cache.set = function(key, value) {
654+
const wrappedSet = function(key, value) {
655655
const result = originalSet(key, value)
656656

657657
// Broadcast to other instances in cluster
@@ -665,7 +665,7 @@ cache.set = function(key, value) {
665665
}
666666

667667
// Wrap invalidate() to broadcast to other instances
668-
cache.invalidate = function(pattern) {
668+
const wrappedInvalidate = function(pattern) {
669669
const keysInvalidated = originalInvalidate(pattern)
670670

671671
// Broadcast to other instances in cluster
@@ -680,8 +680,8 @@ cache.invalidate = function(pattern) {
680680
}
681681

682682
// Wrap clear() to broadcast to other instances
683-
cache.clear = function() {
684-
const entriesCleared = this.length()
683+
const wrappedClear = function() {
684+
const entriesCleared = cache.cache.size
685685
originalClear()
686686

687687
// Broadcast to other instances in cluster
@@ -692,6 +692,11 @@ cache.clear = function() {
692692
return entriesCleared
693693
}
694694

695+
// Replace methods with wrapped versions
696+
cache.set = wrappedSet
697+
cache.invalidate = wrappedInvalidate
698+
cache.clear = wrappedClear
699+
695700
// Add method to get aggregated stats across all instances
696701
cache.getAggregatedStats = async function() {
697702
if (!isClusterMode()) {

0 commit comments

Comments
 (0)