Module: ActiveSupport::Cache::SerializerWithFallback

Included in:
Marshal70WithFallback, Marshal71WithFallback, MessagePackWithFallback, PassthroughWithFallback
Defined in:
lib/active_support/cache/serializer_with_fallback.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Marshal70WithFallback, Marshal71WithFallback, MessagePackWithFallback, PassthroughWithFallback

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](format) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/active_support/cache/serializer_with_fallback.rb', line 9

def self.[](format)
  if format.to_s.include?("message_pack") && !defined?(ActiveSupport::MessagePack)
    require "active_support/message_pack"
  end

  SERIALIZERS.fetch(format)
end

Instance Method Details

#load(dumped) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/active_support/cache/serializer_with_fallback.rb', line 17

def load(dumped)
  if dumped.is_a?(String)
    case
    when MessagePackWithFallback.dumped?(dumped)
      MessagePackWithFallback._load(dumped)
    when Marshal71WithFallback.dumped?(dumped)
      Marshal71WithFallback._load(dumped)
    when Marshal70WithFallback.dumped?(dumped)
      Marshal70WithFallback._load(dumped)
    else
      Cache::Store.logger&.warn("Unrecognized payload prefix #{dumped.byteslice(0).inspect}; deserializing as nil")
      nil
    end
  elsif PassthroughWithFallback.dumped?(dumped)
    PassthroughWithFallback._load(dumped)
  else
    Cache::Store.logger&.warn("Unrecognized payload class #{dumped.class}; deserializing as nil")
    nil
  end
end