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

.storesObject

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

.[](*names) ⇒ AbstractStore?

Cache store lookup.

Parameters:

  • *names (Symbol)

    The name of a registered store.

Returns:



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

.clone_storesObject

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

.default_store_nameObject

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

.exists?(name) ⇒ Boolean

Checks if a given store exists already.

Returns:

  • (Boolean)


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

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

Registers the cache store name with a type & options.

Parameters:

  • name (Symbol)

    An optional symbol to give the cache. :default is used if no name is given.

  • klass (Class) (defaults to: nil)

    A store type.

  • opts (Hash) (defaults to: {})

    A hash to pass through to the store for configuration.

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

.setup(&blk) ⇒ Object



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