Skip to content

Add cache interface for ease of use

Jeremy Jackson requested to merge jj-add-cache-interface into master

This is mostly to abstract away some details about the cache store and improve the interface into it. Is part of https://gitlab.com/gitlab-org/gitlab-experiment/-/issues/17, and I think closes it.

This provides a couple basic methods that we'll be able to use in tooling. I won't bother writing much about the way you used to have to do this, but you don't have to worry about cache keys anymore when interfacing in this way.

An experiment, with a context, can interface with the cache in this way now.

include Gitlab::Experiment::Dsl

experiment(:example, foo: :bar).cache.read # => nil
experiment(:example, foo: :bar).cache.write # defaults to the resolved variant name -- common case.
experiment(:example, foo: :bar).cache.read # => "control"
experiment(:example, foo: :bar).cache.write(:variant_name)
experiment(:example, foo: :bar).cache.read # => "variant_name"
experiment(:example, foo: :bar).cache.delete
experiment(:example, foo: :bar).cache.read # => nil
Edited by Jeremy Jackson

Merge request reports

Loading