Module: ActiveSupport::Cache

Defined in:
lib/gems/activesupport-2.2.2/lib/active_support/cache.rb,
lib/gems/activesupport-2.2.2/lib/active_support/cache/drb_store.rb,
lib/gems/activesupport-2.2.2/lib/active_support/cache/file_store.rb,
lib/gems/activesupport-2.2.2/lib/active_support/cache/memory_store.rb,
lib/gems/activesupport-2.2.2/lib/active_support/cache/mem_cache_store.rb,
lib/gems/activesupport-2.2.2/lib/active_support/cache/synchronized_memory_store.rb,
lib/gems/activesupport-2.2.2/lib/active_support/cache/compressed_mem_cache_store.rb

Overview

See ActiveSupport::Cache::Store for documentation.

Defined Under Namespace

Classes: CompressedMemCacheStore, DRbStore, FileStore, MemCacheStore, MemoryStore, Store, SynchronizedMemoryStore

Class Method Summary collapse

Class Method Details

.expand_cache_key(key, namespace = nil) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gems/activesupport-2.2.2/lib/active_support/cache.rb', line 46

def self.expand_cache_key(key, namespace = nil)
  expanded_cache_key = namespace ? "#{namespace}/" : ""

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

  expanded_cache_key << case
    when key.respond_to?(:cache_key)
      key.cache_key
    when key.is_a?(Array)
      key.collect { |element| expand_cache_key(element) }.to_param
    when key
      key.to_param
    end.to_s

  expanded_cache_key
end

.lookup_store(*store_option) ⇒ Object

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


31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gems/activesupport-2.2.2/lib/active_support/cache.rb', line 31

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