From 6993fb36ac9b0d1d1bbca6d5b8682af03a9007ce Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 1 May 2015 15:25:23 +1000 Subject: [PATCH] FIX: distributed cache failing to clear certain values sometimes this makes the cache resilient to cross machine / forking concerns --- lib/distributed_cache.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/distributed_cache.rb b/lib/distributed_cache.rb index c1c37a7a8ce..44cd2744ff7 100644 --- a/lib/distributed_cache.rb +++ b/lib/distributed_cache.rb @@ -24,7 +24,7 @@ class DistributedCache begin current = @subscribers[i] - next if payload["origin"] == current.object_id + next if payload["origin"] == current.identity next if current.key != payload["hash_key"] hash = current.hash(message.site_id) @@ -61,7 +61,7 @@ class DistributedCache end def self.publish(hash, message) - message[:origin] = hash.object_id + message[:origin] = hash.identity message[:hash_key] = hash.key DiscourseBus.publish(channel_name, message, { user_ids: [-1] }) end @@ -92,6 +92,11 @@ class DistributedCache @data = {} end + def identity + # fork resilient / multi machine identity + (@seed_id ||= SecureRandom.hex) + "#{Process.pid}" + end + def []=(k,v) k = k.to_s if Symbol === k DistributedCache.set(self, k, v)