Module: Merb::Cache

Defined in:
merb-cache/lib/merb-cache/cache.rb,
merb-cache/lib/merb-cache/version.rb,
merb-cache/lib/merb-cache/cache_request.rb,
merb-cache/lib/merb-cache/stores/strategy/page_store.rb,
merb-cache/lib/merb-cache/stores/strategy/gzip_store.rb,
merb-cache/lib/merb-cache/stores/strategy/sha1_store.rb,
merb-cache/lib/merb-cache/stores/strategy/adhoc_store.rb,
merb-cache/lib/merb-cache/stores/strategy/action_store.rb,
merb-cache/lib/merb-cache/stores/fundamental/file_store.rb,
merb-cache/lib/merb-cache/stores/fundamental/memcached_store.rb,
merb-cache/lib/merb-cache/stores/strategy/abstract_strategy_store.rb

Defined Under Namespace

Modules: CacheMixin Classes: AbstractStore, AbstractStrategyStore, ActionStore, AdhocStore, CacheRequest, FileStore, GzipStore, MemcachedStore, NotSupportedError, PageStore, SHA1Store, StoreExists, StoreNotFound

Constant Summary

VERSION =
'1.2.0'.freeze

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Class Attribute Details

+ (Object) stores

Returns the value of attribute stores



34
35
36
# File 'merb-cache/lib/merb-cache/cache.rb', line 34

def stores
  @stores
end

Class Method Details

+ (AbstractStore?) [](*names)

Cache store lookup.



43
44
45
46
47
48
49
50
51
52
# File 'merb-cache/lib/merb-cache/cache.rb', line 43

def self.[](*names)
  if names.size == 1
    Thread.current[:merb-cache'] ||= {}
    (Thread.current[:merb-cache'][names.first] ||= stores[names.first].clone)
  else
    AdhocStore[*names]
  end
rescue TypeError
  raise(StoreNotFound, "Could not find the :#{names.first} store")
end

+ (Object) clone_stores

Clones the cache stores for the current thread.



55
56
57
# File 'merb-cache/lib/merb-cache/cache.rb', line 55

def self.clone_stores
  @stores.inject({}) {|h, (k, s)| h[k] = s.clone; h}
end

+ (Object) default_store_name

Default store name is :default.



83
84
85
# File 'merb-cache/lib/merb-cache/cache.rb', line 83

def self.default_store_name
  :default
end

+ (Boolean) exists?(name)

Checks if a given store exists already.



76
77
78
79
80
# File 'merb-cache/lib/merb-cache/cache.rb', line 76

def self.exists?(name)
  return true if self[name]
rescue StoreNotFound
  return false
end

+ (Object) register(name, klass = nil, opts = {})

Registers the cache store name with a type & options.

Raises:



66
67
68
69
70
71
72
73
# File 'merb-cache/lib/merb-cache/cache.rb', line 66

def self.register(name, klass = nil, opts = {})
  klass, opts = nil, klass if klass.is_a? Hash
  name, klass = default_store_name, name if klass.nil?

  raise StoreExists, "#{name} store already setup" if @stores.has_key?(name)

  @stores[name] = (AdhocStore === klass) ? klass : klass.new(opts)
end

+ (Object) setup(&blk)



9
10
11
12
13
14
15
16
17
# File 'merb-cache/lib/merb-cache/cache.rb', line 9

def self.setup(&blk)
  if Merb::BootLoader.finished?(Merb::BootLoader::BeforeAppLoads)
    instance_eval(&blk) unless blk.nil?
  else
    Merb::BootLoader.before_app_loads do
      instance_eval(&blk) unless blk.nil?
    end
  end
end