From d3285340e8d84fbb3aada32dd9163137601f7a69 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 18 Aug 2016 23:43:07 +0200 Subject: [PATCH] Added cache to attributes_with_associations. --- app/models/application_model.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/models/application_model.rb b/app/models/application_model.rb index 55e7ce7b6..ce7d837ee 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -189,6 +189,10 @@ returns def attributes_with_associations + key = "#{self.class}::aws::#{id}" + cache = Cache.get(key) + return cache if cache + # get relations attributes = self.attributes self.class.reflect_on_all_associations.map { |assoc| @@ -196,6 +200,7 @@ returns next if !respond_to?(real_ids) attributes[real_ids] = send(real_ids) } + Cache.write(key, attributes) attributes end @@ -472,10 +477,14 @@ returns def cache_delete - # delete id caches + # delete by id caches key = "#{self.class}::#{id}" Cache.delete(key) + # delete by id with attributes_with_associations caches + key = "#{self.class}::aws::#{id}" + Cache.delete(key) + # delete old name / login caches if changed? if changes.key?('name') @@ -490,13 +499,13 @@ returns end end - # delete name caches + # delete by name caches if self[:name] key = "#{self.class}::#{self.name}" Cache.delete(key) end - # delete login caches + # delete by login caches return if !self[:login] Cache.delete("#{self.class}::#{login}")