Sha256: a21d307fc1f2d8daea955719795dcb5e23864ca9c7720dcef5765935b055ba76

Contents?: true

Size: 699 Bytes

Versions: 2

Compression:

Stored size: 699 Bytes

Contents

module ActiveRecord #:nodoc:
  class Base
    
    #
    # Convert this record to a tag string.
    #
    def to_interlock_tag
      "#{self.class.name}-#{self.id}".escape_tag_fragment
    end        

    #
    # The expiry callback.
    #
    
    def expire_interlock_keys
      (CACHE.get(Interlock.dependency_key(self.class.base_class)) || {}).each do |key, scope|
        if scope == :all or (scope == :id and key.field(4) == self.to_param.to_s)
          Interlock.say key, "invalidated by rule #{self.class} -> #{scope.inspect}."
          Interlock.invalidate key
        end
      end
    end
    
    before_save :expire_interlock_keys
    after_destroy :expire_interlock_keys

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
interlock-1.1 lib/interlock/active_record.rb
interlock-1.2 lib/interlock/active_record.rb