Type:
Class

An abstract cache store class. There are multiple cache store implementations, each having its own additional features. See the classes under the ActiveSupport::Cache module, e.g. ActiveSupport::Cache::MemCacheStore. MemCacheStore is currently the most popular cache store for large production websites.

Some implementations may not support all methods beyond the basic cache methods of fetch, write, read, exist?, and delete.

ActiveSupport::Cache::Store can store any serializable Ruby object.

cache = ActiveSupport::Cache::MemoryStore.new

cache.read('city')   # => nil
cache.write('city', "Duckburgh")
cache.read('city')   # => "Duckburgh"

Keys are always translated into Strings and are case sensitive. When an object is specified as a key and has a cache_key method defined, this method will be called to define the key. Otherwise, the to_param method will be called. Hashes and Arrays can also be used as keys. The elements will be delimited by slashes, and the elements within a Hash will be sorted by key so they are consistent.

cache.read('city') == cache.read(:city)   # => true

Nil values can be cached.

If your cache is on a shared infrastructure, you can define a namespace for your cache entries. If a namespace is defined, it will be prefixed on to every key. The namespace can be either a static value or a Proc. If it is a Proc, it will be invoked when each key is evaluated so that you can use application logic to invalidate keys.

cache.namespace = -> { @last_mod_time }  # Set the namespace to a variable
@last_mod_time = Time.now  # Invalidate the entire cache by changing namespace

Caches can also store values in a compressed format to save space and reduce time spent sending data. Since there is overhead, values must be large enough to warrant compression. To turn on compression either pass compress: true in the initializer or as an option to fetch or write. To specify the threshold at which to compress values, set the :compress_threshold option. The default threshold is 16K.

new

new(options = nil) Class Public methods Create a new cache. The options will

2015-06-20 00:00:00
key_matcher

key_matcher(pattern, options) Instance Protected methods Add the namespace defined

2015-06-20 00:00:00
read_multi

read_multi(*names) Instance Public methods Read multiple values at once from

2015-06-20 00:00:00
clear

clear(options = nil) Instance Public methods Clear the entire cache. Be careful

2015-06-20 00:00:00
cleanup

cleanup(options = nil) Instance Public methods Cleanup the cache by removing

2015-06-20 00:00:00
exist?

exist?(name, options = nil) Instance Public methods Returns true

2015-06-20 00:00:00
delete

delete(name, options = nil) Instance Public methods Deletes an entry in the

2015-06-20 00:00:00
instrument=

instrument=(boolean) Class Public methods Set to true if cache

2015-06-20 00:00:00
increment

increment(name, amount = 1, options = nil) Instance Public methods Increment

2015-06-20 00:00:00
mute

mute() Instance Public methods Silence the logger within a block.

2015-06-20 00:00:00