Module: CacheUtils::Model

Extended by:
ActiveSupport::Concern
Defined in:
lib/cache_utils/model.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#custom_cache_keyObject



15
16
17
# File 'lib/cache_utils/model.rb', line 15

def custom_cache_key
  self.class.to_s.underscore.pluralize + "/#{id}"
end

#purge_cacheObject



19
20
21
22
23
24
# File 'lib/cache_utils/model.rb', line 19

def purge_cache
  class_keys = self.class.cache_key
  class_keys += extra_class_key if respond_to?(:extra_class_key)
  $redis.del(*($redis.scan_each(match: custom_cache_key + '*').to_a + $redis.scan_each(match: class_keys + '*').to_a))
  Appsignal.increment_counter('cache_purge', 1) if defined?(Appsignal)
end