Module: ManageCache::LocalInstanceMethods

Defined in:
lib/manage_cache.rb

Instance Method Summary collapse

Instance Method Details

#cache_key_for(spec, opts = {}) ⇒ Object



42
43
44
45
# File 'lib/manage_cache.rb', line 42

def cache_key_for(spec, opts={})
  instance_variable_get("@cache_key_for_#{spec}") ||
    instance_variable_set("@cache_key_for_#{spec}", prepare_cache_key(spec, opts))
end

#dump_cache!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/manage_cache.rb', line 24

def dump_cache!
  self.class.cache_keys_specs.each do |key_name, key_specs|
    # the rails helper method 'cache (name, opts) do ...'
    # adds some extras to the cache key.
    # To run with this gem, you have to add 'skip_digest: true'.
    # Any other options will prevent correct cache deletion!!
    #
    [cache_key_for(key_name), "views/#{cache_key_for(key_name)}"].each do |key|
      if !key_specs[:regexp].blank?
        delete_cache_w_regexp(key, key_specs)
      else
        Rails.cache.delete(key)
      end
      instance_variable_set("@cache_key_for_#{key_name}", nil)
    end if delete_cache?(key_specs)
  end
end