Method: ActiveSupport::Cache.lookup_store
- Defined in:
- activesupport/lib/active_support/cache.rb
.lookup_store(store = nil, *parameters) ⇒ Object
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
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'activesupport/lib/active_support/cache.rb', line 85 def lookup_store(store = nil, *parameters) case store when Symbol = parameters. retrieve_store_class(store).new(*parameters, **) when Array lookup_store(*store) when nil ActiveSupport::Cache::MemoryStore.new else store end end |