Sha256: a46509d074f17291a850557ce9ee972ce1e376dde91b38ead59c38caef60e5b6
Contents?: true
Size: 527 Bytes
Versions: 10
Compression:
Stored size: 527 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
10 entries across 10 versions & 1 rubygems