class Split::Cacheable::Adapter
Constants
- DEFAULT_KEY
Public Class Methods
new(controller_instance, action_name)
click to toggle source
# File lib/split_cacheable.rb, line 20 def initialize(controller_instance, action_name) @controller = controller_instance @action_name = action_name end
Public Instance Methods
active_tests()
click to toggle source
Get all tests which should be active on this controller for this action
# File lib/split_cacheable.rb, line 26 def active_tests ab_tests = @controller.class.split_cacheable_ab_tests.select { |test_obj| is_active = false if test_obj[:only].include?(@action_name) is_active = true end if test_obj[:only].empty? && !test_obj[:except].include?(@action_name) is_active = true end # The assumption here is that we should only evaluate the :if Proc or Boolean # if we are part of a live ActionController::Base. # This allows active_tests to return all possible active tests for when you call get_all_possible_variations if (defined?(@controller.request) && !@controller.request.nil?) && test_obj[:if] if is_active && (test_obj[:if].is_a?(Proc) ? test_obj[:if].call(@controller) : !!test_obj[:if]) is_active = true else is_active = false end end is_active } end
get_all_possible_variations()
click to toggle source
Search the Split::ExperimentCatalog to find all tests and generate every possible partial cache key
Use this to clear all your action_caches
# File lib/split_cacheable.rb, line 72 def get_all_possible_variations test_variations = Array.new active_tests.each { |test_obj| split_test = Split::ExperimentCatalog.find(test_obj[:test_name]) if split_test test_variations << split_test.alternatives.map { |alternative| "#{split_test.name}/#{alternative.name}" } end } case test_variations.length when 0 return [DEFAULT_KEY] when 1 test_variations[0].unshift(DEFAULT_KEY) return test_variations[0] else all_variations = [] test_variations.each.with_index(1) do |value, index| test_variations.combination(index).each do |set| all_variations += set.first.product(*set[1..-1]).map{|a| a.join("/")} end end all_variations.unshift(DEFAULT_KEY) return all_variations end end
get_current_variations()
click to toggle source
Use Split
to return a partial cache key (used in fragment_cache_key) by calling ab_test which is an internal Split::Helper method that is now on your controller instance
You should not be calling this method outside of a live ActionController::Base
# File lib/split_cacheable.rb, line 58 def get_current_variations if !defined?(@controller.request) || @controller.request.nil? return DEFAULT_KEY else return !active_tests.empty? ? active_tests.map{ |test_obj| "#{test_obj[:test_name]}/#{@controller.send(:ab_test, test_obj[:test_name])}" }.join('/') : DEFAULT_KEY end end