Fixed bug: ApplicationModel.lookup returns invalid cache entries.
This commit is contained in:
parent
2d70134d72
commit
8096ee0892
1 changed files with 11 additions and 27 deletions
|
@ -14,41 +14,25 @@ module ApplicationModel::HasCache
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_delete
|
def cache_delete
|
||||||
keys = []
|
cache_keys = []
|
||||||
|
|
||||||
# delete by id caches
|
|
||||||
keys.push "#{self.class}::#{id}"
|
|
||||||
|
|
||||||
# delete by id with attributes_with_association_ids caches
|
# delete by id with attributes_with_association_ids caches
|
||||||
keys.push "#{self.class}::aws::#{id}"
|
cache_keys.push "#{self.class}::aws::#{id}"
|
||||||
|
|
||||||
# delete by name caches
|
# delete caches of lookup_keys (e.g. id, name, email, login, number)
|
||||||
if self[:name]
|
self.class.lookup_keys.each do |lookup_key|
|
||||||
keys.push "#{self.class}::#{name}"
|
cache_keys.push "#{self.class}::#{self[lookup_key]}"
|
||||||
|
|
||||||
|
next if !saved_changes? || !saved_changes.key?(lookup_key)
|
||||||
|
|
||||||
|
obsolete_lookup_key = saved_changes[lookup_key][0]
|
||||||
|
cache_keys.push "#{self.class}::#{obsolete_lookup_key}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# delete by login caches
|
cache_keys.each do |key|
|
||||||
if self[:login]
|
|
||||||
keys.push "#{self.class}::#{login}"
|
|
||||||
end
|
|
||||||
|
|
||||||
keys.each do |key|
|
|
||||||
Cache.delete(key)
|
Cache.delete(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
# delete old name / login caches
|
|
||||||
if saved_changes?
|
|
||||||
if saved_changes.key?('name')
|
|
||||||
name = saved_changes['name'][0]
|
|
||||||
key = "#{self.class}::#{name}"
|
|
||||||
Cache.delete(key)
|
|
||||||
end
|
|
||||||
if saved_changes.key?('login')
|
|
||||||
name = saved_changes['login'][0]
|
|
||||||
key = "#{self.class}::#{name}"
|
|
||||||
Cache.delete(key)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue