Sha256: 63cac7ffca67eaa9ecd9bc698ee763573f2e0e753a52d02d932ceba2effaf64e
Contents?: true
Size: 1.09 KB
Versions: 5
Compression:
Stored size: 1.09 KB
Contents
require 'rack/cache/entitystore' module Rack module Cache class EntityStore class RedisBase < self # The underlying ::Redis instance used to communicate with the Redis daemon. attr_reader :cache extend Rack::Utils def open(key) data = read(key) data && [data] end def self.resolve(uri) new ::Redis::Factory.resolve(uri.to_s) end end class Redis < RedisBase def initialize(server, options = {}) @cache = ::Redis.new server end def exist?(key) cache.exists key end def read(key) cache.get key end def write(body, ttl=0) buf = StringIO.new key, size = slurp(body){|part| buf.write(part) } if ttl.zero? [key, size] if cache.set(key, buf.string) else [key, size] if cache.setex(key, ttl, buf.string) end end def purge(key) cache.del key nil end end REDIS = Redis end end end
Version data entries
5 entries across 5 versions & 1 rubygems