method

new

Importance_2
v7.1.3.2 - Show latest stable - 0 notes - Class: RedisCacheStore
new(error_handler: DEFAULT_ERROR_HANDLER, **redis_options) public

Creates a new Redis cache store.

There are four ways to provide the Redis client used by the cache: the :redis param can be a Redis instance or a block that returns a Redis instance, or the :url param can be a string or an array of strings which will be used to create a Redis instance or a +Redis::Distributed+ instance.

Option  Class       Result
:redis  Proc    ->  options[:redis].call
:redis  Object  ->  options[:redis]
:url    String  ->  Redis.new(url: …)
:url    Array   ->  Redis::Distributed.new([{ url: … }, { url: … }, …])

No namespace is set by default. Provide one if the Redis cache server is shared with other apps: namespace: 'myapp-cache'.

Compression is enabled by default with a 1kB threshold, so cached values larger than 1kB are automatically compressed. Disable by passing compress: false or change the threshold by passing compress_threshold: 4.kilobytes.

No expiry is set on cache entries by default. Redis is expected to be configured with an eviction policy that automatically deletes least-recently or -frequently used keys when it reaches max memory. See redis.io/topics/lru-cache for cache server setup.

Race condition TTL is not set by default. This can be used to avoid “thundering herd” cache writes when hot cache entries are expired. See ActiveSupport::Cache::Store#fetch for more.

Setting skip_nil: true will not cache nil results:

cache.fetch('foo') { nil }
cache.fetch('bar', skip_nil: true) { nil }
cache.exist?('foo') # => true
cache.exist?('bar') # => false
Show source
Register or log in to add new notes.