Merge pull request #9825 from huacnlee/cache-application-setting

Add caching for ApplicationSetting, Ci::ApplicationSetting.
This commit is contained in:
Dmitriy Zaporozhets 2015-11-13 10:15:52 +01:00
commit 37465f44b4
2 changed files with 15 additions and 3 deletions

View file

@ -68,8 +68,14 @@ class ApplicationSetting < ActiveRecord::Base
end end
end end
after_commit do
Rails.cache.write('application_setting.last', self)
end
def self.current def self.current
ApplicationSetting.last Rails.cache.fetch('application_setting.last') do
ApplicationSetting.last
end
end end
def self.create_from_defaults def self.create_from_defaults

View file

@ -12,9 +12,15 @@
module Ci module Ci
class ApplicationSetting < ActiveRecord::Base class ApplicationSetting < ActiveRecord::Base
extend Ci::Model extend Ci::Model
after_commit do
Rails.cache.write('ci_application_setting.last', self)
end
def self.current def self.current
Ci::ApplicationSetting.last Rails.cache.fetch('ci_application_setting.last') do
Ci::ApplicationSetting.last
end
end end
def self.create_from_defaults def self.create_from_defaults