Module: Merb::Cache
- Defined in:
- lib/merb-cache/cache.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/strategy/mintcache_store.rb,
lib/merb-cache/stores/fundamental/memcached_store.rb
Defined Under Namespace
Modules: Controller Classes: AbstractStore, ActionStore, AdhocStore, CacheRequest, FileStore, GzipStore, MemcachedStore, MintCacheStore, NotSupportedError, PageStore, SHA1Store, StoreExists, StoreNotFound
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 52 |
# File 'lib/merb-cache/cache.rb', line 42 def self.[](*names) names = names.first if names.first.is_a? Array 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
55 56 57 |
# File 'lib/merb-cache/cache.rb', line 55 def self.clone_stores @stores.inject({}) {|h, (k, s)| h[k] = s.clone; h} end |
.default_store_name ⇒ Object
Default store name is :default.
80 81 82 |
# File 'lib/merb-cache/cache.rb', line 80 def self.default_store_name :default end |
.exists?(name) ⇒ Boolean
Checks to see if a given store exists already.
73 74 75 76 77 |
# File 'lib/merb-cache/cache.rb', line 73 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.
63 64 65 66 67 68 69 70 |
# File 'lib/merb-cache/cache.rb', line 63 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 |