Class: CanTango::Cache::MonetaCache

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/cantango/cache/moneta_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/cantango/cache/moneta_cache.rb', line 6

def options
  @options
end

Instance Method Details

#adapterObject



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

#cacheObject



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 = {}
  @options ||= options
  @type ||= options[: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_statementObject



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_adapterObject



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_adapterObject



54
55
56
# File 'lib/cantango/cache/moneta_cache.rb', line 54

def simple_adapter
  "run #{adapter}"
end

#typeObject



58
59
60
# File 'lib/cantango/cache/moneta_cache.rb', line 58

def type
  (@type == :yaml) ? :YAML : @type
end

#yaml_adapterObject



50
51
52
# File 'lib/cantango/cache/moneta_cache.rb', line 50

def yaml_adapter
  "run #{adapter}, #{options}"
end