Module: Gitlab::Experiment::Cache

Included in:
Gitlab::Experiment
Defined in:
lib/gitlab/experiment/cache.rb,
lib/gitlab/experiment/cache/redis_hash_store.rb

Defined Under Namespace

Classes: Interface, RedisHashStore

Instance Method Summary collapse

Instance Method Details

#cacheObject



42
43
44
# File 'lib/gitlab/experiment/cache.rb', line 42

def cache
  @cache ||= Interface.new(self, Configuration.cache)
end

#cache_key(key = nil, suffix: nil) ⇒ Object



56
57
58
# File 'lib/gitlab/experiment/cache.rb', line 56

def cache_key(key = nil, suffix: nil)
  "#{[name, suffix].compact.join('_')}:#{key || context.signature[:key]}"
end

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



46
47
48
49
50
51
52
53
54
# File 'lib/gitlab/experiment/cache.rb', line 46

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

  result = migrated_cache_fetch(cache.store, &block)
  return result unless specified.present?

  cache.write(specified) if result.to_s != specified.to_s
  specified
end