spread feature flag cache around a ring
Change-Id: I4831cc45d8646f6f86a34ade6546644c4dacdd49 Reviewed-on: https://gerrit.instructure.com/48065 Reviewed-by: Brian Palmer <brianp@instructure.com> Tested-by: Jenkins Product-Review: Cody Cutrer <cody@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
120b052e7a
commit
b1abbc453b
|
@ -232,7 +232,7 @@ class FeatureFlagsController < ApplicationController
|
|||
return render json: { message: "invalid feature" }, status: :bad_request unless feature_def
|
||||
|
||||
# check whether the feature is locked
|
||||
Rails.cache.delete(@context.feature_flag_cache_key(params[:feature]))
|
||||
MultiCache.delete(@context.feature_flag_cache_key(params[:feature]), copies: MultiCache.copies('feature_flags'))
|
||||
current_flag = @context.lookup_feature_flag(params[:feature])
|
||||
if current_flag
|
||||
return render json: { message: "higher account disallows setting feature flag" }, status: :forbidden if current_flag.locked?(@context, @current_user)
|
||||
|
|
|
@ -53,7 +53,7 @@ class FeatureFlag < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def clear_cache
|
||||
connection.after_transaction_commit { Rails.cache.delete(self.context.feature_flag_cache_key(feature)) } if self.context
|
||||
connection.after_transaction_commit { MultiCache.delete(self.context.feature_flag_cache_key(feature), copies: MultiCache.copies('feature_flags')) } if self.context
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -67,7 +67,7 @@ module FeatureFlags
|
|||
# (helper method. use lookup_feature_flag to test policy.)
|
||||
def feature_flag(feature)
|
||||
self.shard.activate do
|
||||
result = Rails.cache.fetch(feature_flag_cache_key(feature)) do
|
||||
result = MultiCache.fetch(feature_flag_cache_key(feature), copies: MultiCache.copies('feature_flags')) do
|
||||
self.feature_flags.where(feature: feature.to_s).first || :nil
|
||||
end
|
||||
result = nil if result == :nil
|
||||
|
|
|
@ -304,7 +304,7 @@ describe "Feature Flags API", type: :request do
|
|||
enable_cache do
|
||||
flag = t_root_account.feature_flags.create! feature: 'course_feature', state: 'on'
|
||||
# try to trick the controller into inserting (and violating a unique constraint) instead of updating
|
||||
Rails.cache.write(cache_key, :nil)
|
||||
MultiCache.fetch(cache_key) { :nil }
|
||||
api_call_as_user(t_root_admin, :put, "/api/v1/accounts/#{t_root_account.id}/features/flags/course_feature?state=off",
|
||||
{ controller: 'feature_flags', action: 'update', format: 'json', account_id: t_root_account.to_param, feature: 'course_feature', state: 'off' })
|
||||
end
|
||||
|
|
|
@ -286,7 +286,7 @@ describe FeatureFlags do
|
|||
end
|
||||
|
||||
describe "caching" do
|
||||
let(:t_cache_key) { t_root_account.feature_flag_cache_key('course_feature') }
|
||||
let(:t_cache_key) { "#{t_root_account.feature_flag_cache_key('course_feature')}:0" }
|
||||
before do
|
||||
t_root_account.feature_flags.create! feature: 'course_feature', state: 'allowed'
|
||||
end
|
||||
|
@ -301,7 +301,7 @@ describe FeatureFlags do
|
|||
it "should cache a nil result" do
|
||||
enable_cache do
|
||||
t_root_account.feature_flag('course_feature2')
|
||||
expect(Rails.cache).to be_exist(t_root_account.feature_flag_cache_key('course_feature2'))
|
||||
expect(Rails.cache).to be_exist("#{t_root_account.feature_flag_cache_key('course_feature2')}:0")
|
||||
t_root_account.expects(:feature_flags).never
|
||||
t_root_account.feature_flag('course_feature2')
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue