Module: Munna::CacheHelper

Defined in:
lib/munna/cache.rb

Class Method Summary collapse

Class Method Details

.delete_key(values, key) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/munna/cache.rb', line 54

def delete_key(values, key)
  values.reject do |k, v|
    if normailize_value(k) == normailize_value(key)
      Rails.cache.delete(k) and true
    end
  end
end

.delete_matched(matches) ⇒ Object



38
39
40
# File 'lib/munna/cache.rb', line 38

def delete_matched(matches)
  matches.each {|k, v| Munna.cache.delete(k)}
end

.get_matched(matches) ⇒ Object



42
43
44
# File 'lib/munna/cache.rb', line 42

def get_matched(matches)
  matches
end

.handle_key(action, key) ⇒ Object



46
47
48
# File 'lib/munna/cache.rb', line 46

def handle_key(action, key)
  Rails.cache.write(Munna::KEY, send("#{action}_key", Munna.cache.values, key))
end

.handle_matched(action, regex) ⇒ Object



33
34
35
36
# File 'lib/munna/cache.rb', line 33

def handle_matched(action, regex)
  matches = Munna.cache.values.select {|v| regex =~ v}
  send("#{action}_matched", matches)
end

.normailize_value(key) ⇒ Object



62
63
64
# File 'lib/munna/cache.rb', line 62

def normailize_value(key)
  key.gsub /-[^\/]+/, ''
end

.write_key(values, key) ⇒ Object



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

def write_key(values, key)
  values[key] = values[key].to_i + 1 and values
end