diff --git a/app/models/category.rb b/app/models/category.rb index c244b7bf3a8..a834d3fd1ed 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -205,14 +205,16 @@ class Category < ActiveRecord::Base # Allows us to skip creating the category definition topic in tests. attr_accessor :skip_category_definition - @topic_id_cache = DistributedCache.new("category_topic_ids") + def self.topic_id_cache + @topic_id_cache ||= DistributedCache.new("category_topic_ids") + end def self.topic_ids - @topic_id_cache.defer_get_set("ids") { Set.new(Category.pluck(:topic_id).compact) } + topic_id_cache.defer_get_set("ids") { Set.new(Category.pluck(:topic_id).compact) } end def self.reset_topic_ids_cache - @topic_id_cache.clear + topic_id_cache.clear end def reset_topic_ids_cache diff --git a/app/models/developer.rb b/app/models/developer.rb index 9ba023ba3c7..458602c1341 100644 --- a/app/models/developer.rb +++ b/app/models/developer.rb @@ -6,14 +6,16 @@ class Developer < ActiveRecord::Base after_save :rebuild_cache after_destroy :rebuild_cache - @id_cache = DistributedCache.new("developer_ids") + def self.id_cache + @id_cache ||= DistributedCache.new("developer_ids") + end def self.user_ids - @id_cache.defer_get_set("ids") { Set.new(Developer.pluck(:user_id)) } + id_cache.defer_get_set("ids") { Set.new(Developer.pluck(:user_id)) } end def self.rebuild_cache - @id_cache.clear + id_cache.clear end def rebuild_cache diff --git a/app/models/theme.rb b/app/models/theme.rb index 6d6db833b00..25fd95c2544 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -10,7 +10,9 @@ class Theme < ActiveRecord::Base attr_accessor :child_components - @cache = DistributedCache.new("theme:compiler:#{BASE_COMPILER_VERSION}") + def self.cache + @cache ||= DistributedCache.new("theme:compiler:#{BASE_COMPILER_VERSION}") + end belongs_to :user belongs_to :color_scheme @@ -202,7 +204,7 @@ class Theme < ActiveRecord::Base end def self.get_set_cache(key, &blk) - @cache.defer_get_set(key, &blk) + cache.defer_get_set(key, &blk) end def self.theme_ids @@ -369,7 +371,7 @@ class Theme < ActiveRecord::Base end def self.clear_cache! - @cache.clear + cache.clear end def self.targets