Module: ActiveSupport::Cache

Defined in:
lib/active_support/cache.rb,
lib/active_support/cache/drb_store.rb,
lib/active_support/cache/file_store.rb,
lib/active_support/cache/memory_store.rb,
lib/active_support/cache/mem_cache_store.rb,
lib/active_support/cache/compressed_mem_cache_store.rb

Defined Under Namespace

Modules: ThreadSafety Classes: CompressedMemCacheStore, DRbStore, FileStore, MemCacheStore, MemoryStore, Store

Class Method Summary collapse

Class Method Details

.expand_cache_key(key, namespace = nil) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/active_support/cache.rb', line 20

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.respond_to?(:to_param)
    key.to_param
  end

  expanded_cache_key
end

.lookup_store(*store_option) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/active_support/cache.rb', line 5

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