Class: ActiveRecord::Base

Inherits:
Object show all
Defined in:
lib/interlock/active_record.rb

Constant Summary collapse

@@nil_sentinel =
:_nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.update_counters_with_expiry(id, counters) ⇒ Object



8
9
10
11
# File 'lib/interlock/active_record.rb', line 8

def update_counters_with_expiry(id, counters)
  update_counters_without_expiry(id, counters)
  find(id).expire_interlock_keys
end

Instance Method Details

#expire_interlock_keysObject

The expiry callback.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/interlock/active_record.rb', line 25

def expire_interlock_keys
  return if Interlock.config[:disabled] or (defined? CGI::Session::ActiveRecordStore and is_a? CGI::Session::ActiveRecordStore::Session)
  
  # Fragments
  self.expire_interlock_keys_for_dependency(Interlock.dependency_key(self.class.base_class, :all, nil))
  self.expire_interlock_keys_for_dependency(Interlock.dependency_key(self.class.base_class, :id, "::::#{to_param}:"))
  
  # Models
  if Interlock.config[:with_finders]
    key = self.class.base_class.caching_key(self.id)
    Interlock.say key, 'invalidated with finders', 'model'
    Interlock.invalidate key
  end
end

#expire_interlock_keys_for_dependency(dependency_key) ⇒ Object



53
54
55
56
57
58
# File 'lib/interlock/active_record.rb', line 53

def expire_interlock_keys_for_dependency(dependency_key)
  (CACHE.get(dependency_key) || {}).each do |key, scope|
    Interlock.say key, "invalidated by rule #{self.class} -> #{scope.inspect}."
    Interlock.invalidate key
  end      
end

#reload_with_expiry(*args) ⇒ Object

Reload. Expires the cache and force reload from db.



47
48
49
50
# File 'lib/interlock/active_record.rb', line 47

def reload_with_expiry(*args)
  expire_interlock_keys
  reload_without_expiry(*args)
end

#to_interlock_tagObject

Convert this record to a tag string.



18
19
20
# File 'lib/interlock/active_record.rb', line 18

def to_interlock_tag
  "#{self.class.name}-#{self.id}".escape_tag_fragment
end