Class: HTTParty::DryIce::IceCache
- Inherits:
-
Object
- Object
- HTTParty::DryIce::IceCache
- Defined in:
- lib/dry_ice.rb
Instance Method Summary collapse
- #build_response(serialized_response) ⇒ Object
- #exist?(*args) ⇒ Boolean
-
#initialize(cache, options = {}) ⇒ IceCache
constructor
A new instance of IceCache.
- #read(*args) ⇒ Object
- #serialize_response(response) ⇒ Object
- #write(name, value, options = {}) ⇒ Object
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 = {:serialize => true}.merge() @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
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, = {}) @cache.write(name, serialize_response(value), ) end |