Sha256: c2f95969ed69f63b5bf0f4b3ed0844b0d19a5c05102a09b5de48fb1dddec4d12

Contents?: true

Size: 899 Bytes

Versions: 1

Compression:

Stored size: 899 Bytes

Contents

module Catche
  module Model
    module Base
      extend ActiveSupport::Concern

      included do
        after_update  :expire_resource_and_collection!
        after_destroy :expire_resource_and_collection!

        after_create  :expire_collection!
      end

      def expire_resource_and_collection!
        expire_collection!
        expire_resource!
      end

      def expire_collection!
        expire_cache! false
      end

      def expire_resource!
        expire_cache!
      end

      def expire_cache!(set_instance=true)
        tags = Catche::Tag::Object.find_by_model(self.class).collect do |obj|
          self.instance_variable_set("@#{obj.options[:resource_name]}", self) if set_instance
          obj.expiration_tags(self)
        end.flatten.compact.uniq

        Catche::Tag.expire! *tags
      end

    end
  end
end

ActiveRecord::Base.send :include, Catche::Model::Base

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
catche-0.1.2 lib/catche/model/base.rb