Sha256: f3193f89dbad15638f788baf2bcff020f16ae6de78a416e25214bf4d82bd1cbd

Contents?: true

Size: 871 Bytes

Versions: 1

Compression:

Stored size: 871 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
      
      # Fragments
      (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
      
      # Models
      if Interlock.config[:with_finders]
        Interlock.invalidate(self.class.caching_key(self.id))
      end
    end
    
    before_save :expire_interlock_keys
    after_destroy :expire_interlock_keys
            
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
interlock-1.3 lib/interlock/active_record.rb