Class: Gitlab::Experiment::Cache::Interface

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/experiment/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(experiment, store) ⇒ Interface

Returns a new instance of Interface.



11
12
13
14
15
# File 'lib/gitlab/experiment/cache.rb', line 11

def initialize(experiment, store)
  @experiment = experiment
  @store = store
  @key = experiment.cache_key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/gitlab/experiment/cache.rb', line 9

def key
  @key
end

#storeObject (readonly)

Returns the value of attribute store.



9
10
11
# File 'lib/gitlab/experiment/cache.rb', line 9

def store
  @store
end

Instance Method Details

#attr_get(name) ⇒ Object



29
30
31
# File 'lib/gitlab/experiment/cache.rb', line 29

def attr_get(name)
  store.read(@experiment.cache_key(name, suffix: :attrs))
end

#attr_inc(name, amount = 1) ⇒ Object



37
38
39
# File 'lib/gitlab/experiment/cache.rb', line 37

def attr_inc(name, amount = 1)
  store.increment(@experiment.cache_key(name, suffix: :attrs), amount)
end

#attr_set(name, value) ⇒ Object



33
34
35
# File 'lib/gitlab/experiment/cache.rb', line 33

def attr_set(name, value)
  store.write(@experiment.cache_key(name, suffix: :attrs), value)
end

#deleteObject



25
26
27
# File 'lib/gitlab/experiment/cache.rb', line 25

def delete
  store.delete(key)
end

#readObject



17
18
19
# File 'lib/gitlab/experiment/cache.rb', line 17

def read
  store.read(key)
end

#write(value = nil) ⇒ Object



21
22
23
# File 'lib/gitlab/experiment/cache.rb', line 21

def write(value = nil)
  store.write(key, value || @experiment.assigned.name)
end