2020-10-27 00:50:13 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
2020-09-24 03:21:30 +08:00
|
|
|
delegate :fetch, :delete, :validate_consul_event, to: :cache
|
2019-08-17 07:09:02 +08:00
|
|
|
|
|
|
|
def cache
|
2020-04-16 06:20:40 +08:00
|
|
|
unless defined?(@multi_cache)
|
2021-04-06 00:14:27 +08:00
|
|
|
ha_cache_config = YAML.safe_load(Canvas::DynamicSettings.find(tree: :private, cluster: Canvas.cluster)["ha_cache.yml"] || "{}").symbolize_keys || {}
|
|
|
|
@multi_cache = if ha_cache_config[:cache_store]
|
2021-09-23 00:25:11 +08:00
|
|
|
ha_cache_config[:url] = ha_cache_config[:servers] if ha_cache_config[:servers]
|
|
|
|
ActiveSupport::Cache.lookup_store(ha_cache_config[:cache_store].to_sym, ha_cache_config)
|
|
|
|
else
|
|
|
|
config = Canvas.cache_store_config_for(Rails.env).dup || {}
|
|
|
|
# MultiCache has to have an expiration
|
|
|
|
config[:expires_in] ||= 300
|
|
|
|
Canvas.lookup_cache_store(config, Rails.env)
|
|
|
|
end
|
2021-04-06 00:14:27 +08:00
|
|
|
@multi_cache.options.delete(:namespace) # remove the namespace that switchman added; MultiCache is global
|
2016-08-03 03:03:43 +08:00
|
|
|
end
|
2021-04-06 00:14:27 +08:00
|
|
|
@multi_cache
|
2016-08-03 03:03:43 +08:00
|
|
|
end
|
2015-02-03 04:26:27 +08:00
|
|
|
|
2019-08-17 07:09:02 +08:00
|
|
|
def reset
|
2020-04-30 03:39:29 +08:00
|
|
|
remove_instance_variable(:@multi_cache) if instance_variable_defined?(:@multi_cache)
|
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
|