Module: ActiveSupport::Cache
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
ConnectionPoolLike
|
|
Defined in: | activesupport/lib/active_support/cache.rb, activesupport/lib/active_support/cache/file_store.rb, activesupport/lib/active_support/cache/mem_cache_store.rb, activesupport/lib/active_support/cache/memory_store.rb, activesupport/lib/active_support/cache/null_store.rb, activesupport/lib/active_support/cache/redis_cache_store.rb, activesupport/lib/active_support/cache/strategy/local_cache.rb, activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb |
Overview
See Store
for documentation.
Constant Summary
-
UNIVERSAL_OPTIONS =
These options mean something to all cache implementations. Individual cache implementations may support additional options.
[:namespace, :compress, :compress_threshold, :expires_in, :race_condition_ttl, :coder]
Class Method Summary
-
.expand_cache_key(key, namespace = nil)
Expands out the
key
argument into a key that can be used for the cache store. -
.lookup_store(store = nil, *parameters)
Creates a new
Store
object according to the given options.
Instance Method Summary
ConnectionPoolLike
- Included
Class Method Details
.expand_cache_key(key, namespace = nil)
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. ([:foo, : ]) # => "foo/bar"
ActiveSupport::Cache. ([:foo, : ], "namespace") # => "namespace/foo/bar"
The key
argument can also respond to cache_key
or to_param
.
# File 'activesupport/lib/active_support/cache.rb', line 89
def (key, namespace = nil) = namespace ? +"#{namespace}/" : +"" if prefix = ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"] << "#{prefix}/" end << retrieve_cache_key(key) end
.lookup_store(store = nil, *parameters)
Creates a new Cache::Store
object according to the given options.
If no arguments are passed to this method, then a new Cache::MemoryStore
object will be returned.
If you pass a ::Symbol
as the first argument, then a corresponding cache store class under the 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
# File 'activesupport/lib/active_support/cache.rb', line 57
def lookup_store(store = nil, *parameters) case store when Symbol = parameters. # clean this up once Ruby 2.7 support is dropped # see https://github.com/rails/rails/pull/41522#discussion_r581186602 if .empty? retrieve_store_class(store).new(*parameters) else retrieve_store_class(store).new(*parameters, ** ) end when Array lookup_store(*store) when nil ActiveSupport::Cache::MemoryStore.new else store end end