Sha256: 2a8ad45970f358166d17623b7e24afcb14837795b5810ad80925ae9f80307286

Contents?: true

Size: 951 Bytes

Versions: 6

Compression:

Stored size: 951 Bytes

Contents

require 'digest/sha1'
require 'rack/utils'
require 'rack/cache/key'
require 'rack/cache/metastore'

module Rack
  module Cache
    class MetaStore
      class RedisBase < self
        extend Rack::Utils

        # The Redis::Store object used to communicate with the Redis daemon.
        attr_reader :cache

        def self.resolve(uri)
          new ::Redis::Factory.resolve(uri.to_s)
        end
      end

      class Redis < RedisBase
        # The Redis instance used to communicated with the Redis daemon.
        attr_reader :cache

        def initialize(server, options = {})
          @cache = ::Redis::Factory.create(server)
        end

        def read(key)
          cache.get(hexdigest(key)) || []
        end

        def write(key, entries)
          cache.set(hexdigest(key), entries)
        end

        def purge(key)
          cache.del(hexdigest(key))
          nil
        end
      end

      REDIS = Redis
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
redis-rack-cache-1.2.1 lib/rack/cache/redis_metastore.rb
redis-rack-cache-1.2 lib/rack/cache/redis_metastore.rb
redis-rack-cache-1.1 lib/rack/cache/redis_metastore.rb
redis-rack-cache-1.1.rc3 lib/rack/cache/redis_metastore.rb
redis-rack-cache-1.1.rc2 lib/rack/cache/redis_metastore.rb
redis-rack-cache-1.1.rc lib/rack/cache/redis_metastore.rb