diff options
author | Stan Hu <stanhu@gmail.com> | 2015-11-25 11:30:33 -0800 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2015-11-25 11:30:33 -0800 |
commit | e55473ad6880a68a86f355b7825dbdaf67e1f375 (patch) | |
tree | d9c7357dd299c47edbd59e5ba7fa5a0033745c15 /app/models/application_setting.rb | |
parent | dee28c50a90acaf1a364d3971132c70c96493932 (diff) | |
download | gitlab-ce-e55473ad6880a68a86f355b7825dbdaf67e1f375.tar.gz |
Expire application settings from cache at startup
If a DB migration occurs, there's a chance that the application settings are
loaded from the cache and provide stale values, causing Error 500s.
This ensures that at startup the settings are always refreshed.
Closes #3643
Diffstat (limited to 'app/models/application_setting.rb')
-rw-r--r-- | app/models/application_setting.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index b2d5fe1558f..3df8135acf1 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -73,15 +73,23 @@ class ApplicationSetting < ActiveRecord::Base end after_commit do - Rails.cache.write('application_setting.last', self) + Rails.cache.write(cache_key, self) end def self.current - Rails.cache.fetch('application_setting.last') do + Rails.cache.fetch(cache_key) do ApplicationSetting.last end end + def self.expire + Rails.cache.delete(cache_key) + end + + def self.cache_key + 'application_setting.last' + end + def self.create_from_defaults create( default_projects_limit: Settings.gitlab['default_projects_limit'], |