Class: OMQ::Ractor::SerializeCache
- Inherits:
-
Object
- Object
- OMQ::Ractor::SerializeCache
- Defined in:
- lib/omq/ractor.rb
Overview
Shared cache for Marshal.dump so fan-out serializes once. The send pump is single-threaded, so identity check suffices.
Instance Method Summary collapse
- #initialize ⇒ SerializeCache constructor
-
#marshal(obj) ⇒ String
Returns the Marshal-dumped bytes for
obj, reusing the cached result ifobjis the same object as the last call.
Constructor Details
#initialize ⇒ SerializeCache
63 64 65 66 |
# File 'lib/omq/ractor.rb', line 63 def initialize @last = nil @bytes = nil end |
Instance Method Details
#marshal(obj) ⇒ String
Returns the Marshal-dumped bytes for obj, reusing the cached result
if obj is the same object as the last call.
74 75 76 77 78 |
# File 'lib/omq/ractor.rb', line 74 def marshal(obj) return @bytes if obj.equal?(@last) @last = obj @bytes = Marshal.dump(obj).freeze end |