module Gitlab::Experiment::Cache
Public Instance Methods
cache()
click to toggle source
# File lib/gitlab/experiment/cache.rb, line 44 def cache @cache ||= Interface.new(self, Configuration.cache) end
cache_key(key = nil, suffix: nil)
click to toggle source
# File lib/gitlab/experiment/cache.rb, line 58 def cache_key(key = nil, suffix: nil) "#{[name, suffix].compact.join('_')}:#{key || context.signature[:key]}" end
cache_variant(specified = nil) { || ... }
click to toggle source
# File lib/gitlab/experiment/cache.rb, line 48 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 != specified specified end
Private Instance Methods
migrated_cache_fetch(store, &block)
click to toggle source
# File lib/gitlab/experiment/cache.rb, line 64 def migrated_cache_fetch(store, &block) migrations = context.signature[:migration_keys]&.map { |key| cache_key(key) } || [] migrations.find do |old_key| next unless (value = store.read(old_key)) store.write(cache_key, value) store.delete(old_key) return value end store.fetch(cache_key, &block) end