diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 73b8e32c999..3429434473e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -7,6 +7,7 @@ require_dependency 'rate_limiter' require_dependency 'crawler_detection' require_dependency 'json_error' require_dependency 'letter_avatar' +require_dependency 'distributed_cache' class ApplicationController < ActionController::Base include CurrentUser @@ -271,11 +272,21 @@ class ApplicationController < ActionController::Base MultiJson.dump(data) end - def banner_json - topic = Topic.where(archetype: Archetype.banner).limit(1).first - banner = topic.present? ? topic.banner : {} + def self.banner_json_cache + @banner_json_cache ||= DistributedCache.new("banner_json") + end - MultiJson.dump(banner) + def banner_json + + json = ApplicationController.banner_json_cache["json"] + + unless json + topic = Topic.where(archetype: Archetype.banner).limit(1).first + banner = topic.present? ? topic.banner : {} + ApplicationController.banner_json_cache["json"] = json = MultiJson.dump(banner) + end + + json end def render_json_error(obj) diff --git a/app/models/topic.rb b/app/models/topic.rb index a2a35d229de..9eae898bb37 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -172,6 +172,12 @@ class Topic < ActiveRecord::Base unless skip_callbacks schedule_auto_close_job end + + banner = "banner".freeze + + if archetype_was == banner || archetype == banner + ApplicationController.banner_json_cache.clear + end end def initialize_default_values