Class: WithTimedCache::Caches
- Inherits:
-
Object
- Object
- WithTimedCache::Caches
- Defined in:
- lib/with_timed_cache/caches.rb
Class Method Summary collapse
- .cache_class(format = "") ⇒ Object
- .create(key, opts = {}) ⇒ Object
- .find(key) ⇒ Object
- .find_or_create(key, opts = {}) ⇒ Object
Class Method Details
.cache_class(format = "") ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/with_timed_cache/caches.rb', line 27 def cache_class(format = "") format = format.to_s.upcase begin # Ruby Version 1.9 and earlier will choke on this line Object.const_get("WithTimedCache::#{format}Cache") rescue raise WithTimedCache::InvalidCacheFormatException end end |
.create(key, opts = {}) ⇒ Object
23 24 25 |
# File 'lib/with_timed_cache/caches.rb', line 23 def create(key, opts = {}) cache_class(opts[:format]).new(key, opts) end |
.find(key) ⇒ Object
19 20 21 |
# File 'lib/with_timed_cache/caches.rb', line 19 def find(key) @caches.select { |c| c.key == key }.first end |
.find_or_create(key, opts = {}) ⇒ Object
13 14 15 16 17 |
# File 'lib/with_timed_cache/caches.rb', line 13 def find_or_create(key, opts = {}) cache = find(key) || create(key, opts) @caches << cache cache end |