Class: CanTango::Cache::MonetaCache
- Inherits:
-
Object
- Object
- CanTango::Cache::MonetaCache
- Includes:
- Singleton
- Defined in:
- lib/cantango/cache/moneta_cache.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #adapter ⇒ Object
- #cache ⇒ Object
- #configure_with(options = {}) ⇒ Object
- #delete(key) ⇒ Object
- #factory_statement ⇒ Object
- #load!(key) ⇒ Object
- #run_adapter ⇒ Object
- #save!(key, rules) ⇒ Object
- #simple_adapter ⇒ Object
- #type ⇒ Object
- #yaml_adapter ⇒ Object
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/cantango/cache/moneta_cache.rb', line 6 def @options end |
Instance Method Details
#adapter ⇒ Object
62 63 64 65 |
# File 'lib/cantango/cache/moneta_cache.rb', line 62 def adapter require "moneta/adapters/#{type}" @adapter = "Moneta::Adapters::#{type.to_s.camelize}".constantize end |
#cache ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/cantango/cache/moneta_cache.rb', line 25 def cache @cache ||= begin moneta = eval(factory_statement) moneta.clear moneta end end |
#configure_with(options = {}) ⇒ Object
8 9 10 11 |
# File 'lib/cantango/cache/moneta_cache.rb', line 8 def configure_with = {} @options ||= @type ||= [:type] || CanTango.config.cache.store.default_type end |
#delete(key) ⇒ Object
21 22 23 |
# File 'lib/cantango/cache/moneta_cache.rb', line 21 def delete key cache.delete key end |
#factory_statement ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/cantango/cache/moneta_cache.rb', line 33 def factory_statement %{ ::Moneta::Builder.build do #{run_adapter} end } end |
#load!(key) ⇒ Object
13 14 15 |
# File 'lib/cantango/cache/moneta_cache.rb', line 13 def load! key cache[key] end |
#run_adapter ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/cantango/cache/moneta_cache.rb', line 41 def run_adapter case type.to_sym when :yaml yaml_adapter else simple_adapter end end |
#save!(key, rules) ⇒ Object
17 18 19 |
# File 'lib/cantango/cache/moneta_cache.rb', line 17 def save! key, rules cache.store key, rules end |
#simple_adapter ⇒ Object
54 55 56 |
# File 'lib/cantango/cache/moneta_cache.rb', line 54 def simple_adapter "run #{adapter}" end |
#type ⇒ Object
58 59 60 |
# File 'lib/cantango/cache/moneta_cache.rb', line 58 def type (@type == :yaml) ? :YAML : @type end |
#yaml_adapter ⇒ Object
50 51 52 |
# File 'lib/cantango/cache/moneta_cache.rb', line 50 def yaml_adapter "run #{adapter}, #{}" end |