Merb::Cache

Constants

VERSION

Attributes

stores[RW]

Public Class Methods

[](*names) click to toggle source

Cache store lookup name<Symbol> : The name of a registered store Returns<Nil AbstractStore> : A thread-safe copy of the store

# File lib/merb-cache/cache.rb, line 42
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_stores() click to toggle source

Clones the cache stores for the current thread

# File lib/merb-cache/cache.rb, line 54
def self.clone_stores
  @stores.inject({}) {|h, (k, s)| h[k] = s.clone; h}
end
default_store_name() click to toggle source

Default store name is :default.

# File lib/merb-cache/cache.rb, line 79
def self.default_store_name
  :default
end
exists?(name) click to toggle source

Checks to see if a given store exists already.

# File lib/merb-cache/cache.rb, line 72
def self.exists?(name)
  return true if self[name]
rescue StoreNotFound
  return false
end
register(name, klass = nil, opts = {}) click to toggle source

Registers the cache store name with a type & options name<Symbol> : An optional symbol to give the cache. :default is used if no name is given. klass<Class> : A store type. opts<Hash> : A hash to pass through to the store for configuration.

# File lib/merb-cache/cache.rb, line 62
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) click to toggle source
# File 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.