class ActiveSupport::Cache::RedisStore

Public Class Methods

new(*options) click to toggle source
Calls superclass method
# File lib/active_support/cache/redis_store.rb, line 5
def initialize(*options)
  options = options.extract_options!
  super(options)
  extend Strategy::LocalCache
end

Public Instance Methods

clear(options = nil) click to toggle source

Clear the entire cache on server. This method should be used with care when shared cache is being used.

# File lib/active_support/cache/redis_store.rb, line 20
def clear(options = nil)
  redis.flushdb
end
read_multi(*names) click to toggle source

Reads multiple values from the cache using a single call to the servers for all keys.

# File lib/active_support/cache/redis_store.rb, line 13
def read_multi(*names)
  values = redis.mget *names
  values.map{ |v| Redis::Marshal.load(v) }
end

Protected Instance Methods

delete_entry(key, options) click to toggle source

Delete an entry from the cache.

# File lib/active_support/cache/redis_store.rb, line 40
def delete_entry(key, options)
  redis.del(key)
end
read_entry(key, options) click to toggle source

Read an entry from the cache.

# File lib/active_support/cache/redis_store.rb, line 27
def read_entry(key, options)
  Redis::Marshal.load(redis.get(key))
end
write_entry(key, entry, options) click to toggle source

Write an entry to the cache.

# File lib/active_support/cache/redis_store.rb, line 32
def write_entry(key, entry, options)
  method = options && options[:unless_exist] ? :setnx : :set
  expires_in = options[:expires_in].to_i
  redis.send(method, key, Redis::Marshal.dump(entry))
  redis.expire(key, expires_in) if expires_in > 0
end