Sha256: 3e7030c1df166517a8999345fc52a816bd9cfa5c50e9546484468b94f6407912
Contents?: true
Size: 674 Bytes
Versions: 2
Compression:
Stored size: 674 Bytes
Contents
module Rhinestone class Cache takes :cache_backend class KeyNotFound < RuntimeError; end def set(url, response) cache_backend.set("status:#{url}", response.status.to_s) cache_backend.set("headers:#{url}", response.headers.to_yaml) cache_backend.set("body:#{url}", response.body) end def get(url) status = get!("status:#{url}").to_i headers = YAML.load(get!("headers:#{url}")) body = get!("body:#{url}") return Rhinestone::Response.new(status, headers, body) rescue KeyNotFound return nil end private def get!(key) cache_backend.get(key) or raise KeyNotFound end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rhinestone-0.0.2 | lib/rhinestone/cache.rb |
rhinestone-0.0.1 | lib/rhinestone/cache.rb |