@@ -651,7 +651,7 @@ const originalInvalidate = cache.invalidate.bind(cache)
651651const 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
696701cache . getAggregatedStats = async function ( ) {
697702 if ( ! isClusterMode ( ) ) {
0 commit comments