Class: Munna::Cache

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

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



7
8
9
# File 'lib/munna/cache.rb', line 7

def initialize
  values
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/munna/cache.rb', line 20

def method_missing(name, *args, &block)
  if /^write$|^delete$/ =~ name.to_s
    CacheHelper.handle_key(name, args.first)
  elsif /(?<type>.+)_matched$/ =~ name.to_s
    CacheHelper.handle_matched(type, args.first)
  else
    super(name, *args, &block)
  end
end

Instance Method Details

#clearObject



15
16
17
18
# File 'lib/munna/cache.rb', line 15

def clear
  values.keys.each {|k| Rails.cache.delete k }
  Rails.cache.delete(Munna::KEY)
end

#valuesObject



11
12
13
# File 'lib/munna/cache.rb', line 11

def values
  Rails.cache.fetch(Munna::KEY) { Hash.new }
end