DEV: Make every DistributedCache lazily instantiated (#23147)
This commit is contained in:
parent
87ebbec9b2
commit
91f560a521
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue