module ActiveSupport::Cache

Included modules:
ActiveSupport::Cache::ConnectionPoolLike

See ActiveSupport::Cache::Store for documentation.

Constants

UNIVERSAL_OPTIONS

These options mean something to all cache implementations. Individual cache implementations may support additional options.

Public Class Methods

expand_cache_key(key, namespace = nil) Show source
# File activesupport/lib/active_support/cache.rb, line 80
def expand_cache_key(key, namespace = nil)
  expanded_cache_key = (namespace ? "#{namespace}/" : "").dup

  if prefix = ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"]
    expanded_cache_key << "#{prefix}/"
  end

  expanded_cache_key << retrieve_cache_key(key)
  expanded_cache_key
end

Expands out the key argument into a key that can be used for the cache store. Optionally accepts a namespace, and all keys will be scoped within that namespace.

If the key argument provided is an array, or responds to to_a, then each of elements in the array will be turned into parameters/keys and concatenated into a single key. For example:

ActiveSupport::Cache.expand_cache_key([:foo, :bar])               # => "foo/bar"
ActiveSupport::Cache.expand_cache_key([:foo, :bar], "namespace")  # => "namespace/foo/bar"

The key argument can also respond to cache_key or to_param.

lookup_store(*store_option) Show source
# File activesupport/lib/active_support/cache.rb, line 55
def lookup_store(*store_option)
  store, *parameters = *Array.wrap(store_option).flatten

  case store
  when Symbol
    retrieve_store_class(store).new(*parameters)
  when nil
    ActiveSupport::Cache::MemoryStore.new
  else
    store
  end
end

Creates a new Store object according to the given options.

If no arguments are passed to this method, then a new ActiveSupport::Cache::MemoryStore object will be returned.

If you pass a Symbol as the first argument, then a corresponding cache store class under the ActiveSupport::Cache namespace will be created. For example:

ActiveSupport::Cache.lookup_store(:memory_store)
# => returns a new ActiveSupport::Cache::MemoryStore object

ActiveSupport::Cache.lookup_store(:mem_cache_store)
# => returns a new ActiveSupport::Cache::MemCacheStore object

Any additional arguments will be passed to the corresponding cache store class's constructor:

ActiveSupport::Cache.lookup_store(:file_store, '/tmp/cache')
# => same as: ActiveSupport::Cache::FileStore.new('/tmp/cache')

If the first argument is not a Symbol, then it will simply be returned:

ActiveSupport::Cache.lookup_store(MyOwnCacheStore.new)
# => returns MyOwnCacheStore.new

© 2004–2019 David Heinemeier Hansson
Licensed under the MIT License.