Module: Merb::Cache
- Defined in:
- lib/merb-cache/cache.rb,
lib/merb-cache/version.rb,
lib/merb-cache/cache_request.rb,
lib/merb-cache/stores/strategy/gzip_store.rb,
lib/merb-cache/stores/strategy/page_store.rb,
lib/merb-cache/stores/strategy/sha1_store.rb,
lib/merb-cache/stores/strategy/adhoc_store.rb,
lib/merb-cache/stores/strategy/action_store.rb,
lib/merb-cache/stores/fundamental/file_store.rb,
lib/merb-cache/stores/fundamental/memcached_store.rb,
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 collapse
- VERSION =
'1.1.3'.freeze
Class Attribute Summary collapse
-
.stores ⇒ Object
Returns the value of attribute stores.
Class Method Summary collapse
-
.[](*names) ⇒ Object
Cache store lookup name<Symbol> : The name of a registered store Returns<Nil AbstractStore> : A thread-safe copy of the store.
-
.clone_stores ⇒ Object
Clones the cache stores for the current thread.
-
.default_store_name ⇒ Object
Default store name is :default.
-
.exists?(name) ⇒ Boolean
Checks to see if a given store exists already.
-
.register(name, klass = nil, opts = {}) ⇒ Object
Registers the cache store name with a type & options name<Symbol> : An optional symbol to give the cache.
- .setup(&blk) ⇒ Object
Class Attribute Details
.stores ⇒ Object
Returns the value of attribute stores.
34 35 36 |
# File 'lib/merb-cache/cache.rb', line 34 def stores @stores end |
Class Method Details
.[](*names) ⇒ Object
Cache store lookup name<Symbol> : The name of a registered store Returns<Nil AbstractStore> : A thread-safe copy of the store
42 43 44 45 46 47 48 49 50 51 |
# 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 ⇒ Object
Clones the cache stores for the current thread
54 55 56 |
# 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 ⇒ Object
Default store name is :default.
79 80 81 |
# File 'lib/merb-cache/cache.rb', line 79 def self.default_store_name :default end |
.exists?(name) ⇒ Boolean
Checks to see if a given store exists already.
72 73 74 75 76 |
# 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 = {}) ⇒ Object
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.
62 63 64 65 66 67 68 69 |
# 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 |