class method self.lookup_store

Ruby on Rails 2.3.18

Since v2.2.3

Available in: v2.2.3 v2.3.18 v3.0.20 v3.1.12 v3.2.22.5 v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

self.lookup_store(*store_option)

Creates a new CacheStore 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(:drb_store)
# => returns a new ActiveSupport::Cache::DRbStore 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

Parameters

store_option rest
Source
# File activesupport/lib/active_support/cache.rb, line 42
    def self.lookup_store(*store_option)
      store, *parameters = *([ store_option ].flatten)

      case store
      when Symbol
        store_class_name = (store == :drb_store ? "DRbStore" : store.to_s.camelize)
        store_class = ActiveSupport::Cache.const_get(store_class_name)
        store_class.new(*parameters)
      when nil
        ActiveSupport::Cache::MemoryStore.new
      else
        store
      end
    end

Defined in activesupport/lib/active_support/cache.rb line 42 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::Cache

Type at least 2 characters to search.

↑↓ navigate · open · esc close