mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FIX: distributed cache failing to clear certain values sometimes
this makes the cache resilient to cross machine / forking concerns
This commit is contained in:
parent
f9069c350f
commit
6993fb36ac
1 changed files with 7 additions and 2 deletions
|
@ -24,7 +24,7 @@ class DistributedCache
|
||||||
begin
|
begin
|
||||||
current = @subscribers[i]
|
current = @subscribers[i]
|
||||||
|
|
||||||
next if payload["origin"] == current.object_id
|
next if payload["origin"] == current.identity
|
||||||
next if current.key != payload["hash_key"]
|
next if current.key != payload["hash_key"]
|
||||||
|
|
||||||
hash = current.hash(message.site_id)
|
hash = current.hash(message.site_id)
|
||||||
|
@ -61,7 +61,7 @@ class DistributedCache
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.publish(hash, message)
|
def self.publish(hash, message)
|
||||||
message[:origin] = hash.object_id
|
message[:origin] = hash.identity
|
||||||
message[:hash_key] = hash.key
|
message[:hash_key] = hash.key
|
||||||
DiscourseBus.publish(channel_name, message, { user_ids: [-1] })
|
DiscourseBus.publish(channel_name, message, { user_ids: [-1] })
|
||||||
end
|
end
|
||||||
|
@ -92,6 +92,11 @@ class DistributedCache
|
||||||
@data = {}
|
@data = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def identity
|
||||||
|
# fork resilient / multi machine identity
|
||||||
|
(@seed_id ||= SecureRandom.hex) + "#{Process.pid}"
|
||||||
|
end
|
||||||
|
|
||||||
def []=(k,v)
|
def []=(k,v)
|
||||||
k = k.to_s if Symbol === k
|
k = k.to_s if Symbol === k
|
||||||
DistributedCache.set(self, k, v)
|
DistributedCache.set(self, k, v)
|
||||||
|
|
Loading…
Reference in a new issue