mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:23:25 +08:00
FIX: DistributedCache would fail serialization in some cases
This commit is contained in:
parent
96380bfd38
commit
1d27b33100
|
@ -3,6 +3,7 @@
|
|||
# fill it up
|
||||
|
||||
require 'weakref'
|
||||
require 'base64'
|
||||
|
||||
class DistributedCache
|
||||
@subscribers = []
|
||||
|
@ -31,7 +32,7 @@ class DistributedCache
|
|||
hash = current.hash(message.site_id)
|
||||
|
||||
case payload["op"]
|
||||
when "set" then hash[payload["key"]] = payload["marshalled"] ? Marshal.load(payload["value"]) : payload["value"]
|
||||
when "set" then hash[payload["key"]] = payload["marshalled"] ? Marshal.load(Base64.decode64(payload["value"])) : payload["value"]
|
||||
when "delete" then hash.delete(payload["key"])
|
||||
when "clear" then hash.clear
|
||||
end
|
||||
|
@ -70,8 +71,8 @@ class DistributedCache
|
|||
|
||||
def self.set(hash, key, value)
|
||||
# special support for set
|
||||
marshal = Set === value
|
||||
value = Marshal.dump(value) if marshal
|
||||
marshal = (Set === value || Hash === value)
|
||||
value = Base64.encode64(Marshal.dump(value)) if marshal
|
||||
publish(hash, { op: :set, key: key, value: value, marshalled: marshal })
|
||||
end
|
||||
|
||||
|
|
|
@ -15,10 +15,11 @@ describe DistributedCache do
|
|||
c1 = DistributedCache.new("test1")
|
||||
c2 = DistributedCache.new("test1")
|
||||
|
||||
set = {a: 1, b: 1}
|
||||
set = Set.new
|
||||
set << 1
|
||||
set << "b"
|
||||
set << 92803984
|
||||
set << 93739739873973
|
||||
|
||||
c1["cats"] = set
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user