Added cache to attributes_with_associations.

This commit is contained in:
Martin Edenhofer 2016-08-18 23:43:07 +02:00
parent 8a36fac9fd
commit d3285340e8

View file

@ -189,6 +189,10 @@ returns
def attributes_with_associations def attributes_with_associations
key = "#{self.class}::aws::#{id}"
cache = Cache.get(key)
return cache if cache
# get relations # get relations
attributes = self.attributes attributes = self.attributes
self.class.reflect_on_all_associations.map { |assoc| self.class.reflect_on_all_associations.map { |assoc|
@ -196,6 +200,7 @@ returns
next if !respond_to?(real_ids) next if !respond_to?(real_ids)
attributes[real_ids] = send(real_ids) attributes[real_ids] = send(real_ids)
} }
Cache.write(key, attributes)
attributes attributes
end end
@ -472,10 +477,14 @@ returns
def cache_delete def cache_delete
# delete id caches # delete by id caches
key = "#{self.class}::#{id}" key = "#{self.class}::#{id}"
Cache.delete(key) Cache.delete(key)
# delete by id with attributes_with_associations caches
key = "#{self.class}::aws::#{id}"
Cache.delete(key)
# delete old name / login caches # delete old name / login caches
if changed? if changed?
if changes.key?('name') if changes.key?('name')
@ -490,13 +499,13 @@ returns
end end
end end
# delete name caches # delete by name caches
if self[:name] if self[:name]
key = "#{self.class}::#{self.name}" key = "#{self.class}::#{self.name}"
Cache.delete(key) Cache.delete(key)
end end
# delete login caches # delete by login caches
return if !self[:login] return if !self[:login]
Cache.delete("#{self.class}::#{login}") Cache.delete("#{self.class}::#{login}")