Class: OMQ::Ractor::SerializeCache

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeSerializeCache



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.

Parameters:

  • obj (Object)

    object to serialize

Returns:

  • (String)

    frozen Marshal bytes



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