Class: HTTParty::DryIce::IceCache

Inherits:
Object
  • Object
show all
Defined in:
lib/dry_ice.rb

Instance Method Summary collapse

Constructor Details

#initialize(cache, options = {}) ⇒ IceCache

Returns a new instance of IceCache.



105
106
107
108
# File 'lib/dry_ice.rb', line 105

def initialize(cache, options = {})
  @options = {:serialize => true}.merge(options)
  @cache = cache
end

Instance Method Details

#build_response(serialized_response) ⇒ Object



126
127
128
129
130
131
# File 'lib/dry_ice.rb', line 126

def build_response(serialized_response)
  if @options[:serialize]
    serialized_response = MessagePack.unpack(serialized_response)
  end
  CachedHTTPartyResponse.new(serialized_response[0], serialized_response[1], serialized_response[2])
end

#exist?(*args) ⇒ Boolean

Returns:

  • (Boolean)


138
139
140
# File 'lib/dry_ice.rb', line 138

def exist?(*args)
  @cache.exist?(*args)
end

#read(*args) ⇒ Object



133
134
135
136
# File 'lib/dry_ice.rb', line 133

def read(*args)
  found = @cache.read(*args)
  build_response(found) if found
end

#serialize_response(response) ⇒ Object



115
116
117
118
119
120
121
122
123
124
# File 'lib/dry_ice.rb', line 115

def serialize_response(response)
  headers = response.headers.dup
  body = response.body.dup
  parsed_response = response.parsed_response
  if @options[:serialize]
    [headers,body,parsed_response].to_msgpack
  else
    [headers,body,parsed_response]
  end
end

#write(name, value, options = {}) ⇒ Object



110
111
112
# File 'lib/dry_ice.rb', line 110

def write(name, value, options = {})
  @cache.write(name, serialize_response(value), options)
end