Sha256: d8bc5c8978feaffb59c92d016338b57b4c4b83093dacbe21a575f70cd846e220
Contents?: true
Size: 526 Bytes
Versions: 30
Compression:
Stored size: 526 Bytes
Contents
module Concerns module Cacheable extend ActiveSupport::Concern included do after_save :flush_cache after_touch :flush_cache scope :find_in_cache, ->(value) { Rails.cache.fetch [name, value] do find_by!(@cache_field => value) end } end module ClassMethods def cache_by(field) @cache_field = field define_method(:flush_cache) do Rails.cache.delete [self.class.name, self.send(field)] end end end end end
Version data entries
30 entries across 30 versions & 1 rubygems