class HTTParty::DryIce::IceCache

Public Class Methods

new(cache, options = {}) click to toggle source
# File lib/dry_ice.rb, line 105
def initialize(cache, options = {})
  @options = {:serialize => true}.merge(options)
  @cache = cache
end

Public Instance Methods

build_response(serialized_response) click to toggle source
# 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) click to toggle source
# File lib/dry_ice.rb, line 138
def exist?(*args)
  @cache.exist?(*args)
end
read(*args) click to toggle source
# File lib/dry_ice.rb, line 133
def read(*args)
  found = @cache.read(*args)
  build_response(found) if found
end
serialize_response(response) click to toggle source
# 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 = {}) click to toggle source
# File lib/dry_ice.rb, line 110
def write(name, value, options = {})
  @cache.write(name, serialize_response(value), options)
end