Module: Gitlab::Experiment::Caching

Included in:
Gitlab::Experiment
Defined in:
lib/gitlab/experiment/caching.rb

Instance Method Summary collapse

Instance Method Details

#cache_key(key = nil) ⇒ Object



18
19
20
# File 'lib/gitlab/experiment/caching.rb', line 18

def cache_key(key = nil)
  "#{name}:#{key || context.signature[:key]}"
end

#cache_variant(specified = nil, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/gitlab/experiment/caching.rb', line 6

def cache_variant(specified = nil, &block)
  cache = Configuration.cache
  return (specified.presence || yield) unless cache

  key, migrations = cache_strategy
  result = migrated_cache(cache, migrations || [], key) || cache.fetch(key, &block)
  return result unless specified.present?

  cache.write(cache_key, specified) if result != specified
  specified
end