2014-10-10 02:53:39 +08:00
|
|
|
#
|
2017-04-28 04:05:04 +08:00
|
|
|
# Copyright (C) 2011 - present Instructure, Inc.
|
2014-10-10 02:53:39 +08:00
|
|
|
#
|
|
|
|
# This file is part of Canvas.
|
|
|
|
#
|
|
|
|
# Canvas is free software: you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
# Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License along
|
|
|
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
2019-08-17 07:09:02 +08:00
|
|
|
class MultiCache
|
|
|
|
class << self
|
|
|
|
delegate :fetch, :delete, to: :cache
|
|
|
|
|
|
|
|
def cache
|
|
|
|
@multi_cache ||= begin
|
|
|
|
ha_cache_config = YAML.load(Canvas::DynamicSettings.find(tree: :private, cluster: ApplicationController.cluster)["ha_cache.yml"] || "{}").symbolize_keys || {}
|
|
|
|
if (ha_cache_config[:cache_store])
|
|
|
|
ha_cache_config[:url] = ha_cache_config[:servers] if ha_cache_config[:servers]
|
|
|
|
store = ActiveSupport::Cache.lookup_store(ha_cache_config[:cache_store].to_sym, ha_cache_config)
|
|
|
|
store.options.delete(:namespace)
|
|
|
|
store
|
2016-09-13 01:06:12 +08:00
|
|
|
else
|
2019-08-17 07:09:02 +08:00
|
|
|
Rails.cache
|
2016-08-03 03:03:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-02-03 04:26:27 +08:00
|
|
|
|
2019-08-17 07:09:02 +08:00
|
|
|
def reset
|
|
|
|
@multi_cache = nil
|
2015-02-03 04:26:27 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-17 07:09:02 +08:00
|
|
|
Canvas::Reloader.on_reload { reset }
|
2014-10-10 02:53:39 +08:00
|
|
|
end
|