Class: Shipeasy::SDK::InMemoryStickyStore
- Inherits:
-
Object
- Object
- Shipeasy::SDK::InMemoryStickyStore
- Defined in:
- lib/shipeasy/sdk/sticky_store.rb
Overview
Pluggable sticky-bucketing store for the server (doc 20 §2). Duck-typed: any object responding to the two methods below works.
get(unit) -> { exp_name => { "g" => group, "s" => salt8 } } or nil
set(unit, exp_name, entry) # entry = { "g" => group, "s" => salt8 }
Keyed by the bucketing unit (pick_identifier-resolved id). When threaded into experiment eval, an enrolled unit locks to its first-assigned variant — changing allocation % or weights won’t re-bucket it; changing the experiment salt is the reshuffle lever. Absent ⇒ deterministic behavior.
Instance Method Summary collapse
-
#get(unit) ⇒ Object
Return this unit’s per-experiment assignments, or nil if none.
-
#initialize(seed = nil) ⇒ InMemoryStickyStore
constructor
Optionally seed with { unit => { exp => { “g”=>.., “s”=>.. } } }.
-
#set(unit, exp, entry) ⇒ Object
Persist one assignment for (unit, exp).
Constructor Details
#initialize(seed = nil) ⇒ InMemoryStickyStore
Optionally seed with { unit => { exp => { “g”=>.., “s”=>.. } } }.
17 18 19 20 21 22 23 |
# File 'lib/shipeasy/sdk/sticky_store.rb', line 17 def initialize(seed = nil) @mutex = Mutex.new @data = {} if seed seed.each { |unit, exps| @data[unit.to_s] = exps.dup } end end |
Instance Method Details
#get(unit) ⇒ Object
Return this unit’s per-experiment assignments, or nil if none.
26 27 28 |
# File 'lib/shipeasy/sdk/sticky_store.rb', line 26 def get(unit) @mutex.synchronize { @data[unit.to_s] } end |
#set(unit, exp, entry) ⇒ Object
Persist one assignment for (unit, exp).
31 32 33 34 35 36 |
# File 'lib/shipeasy/sdk/sticky_store.rb', line 31 def set(unit, exp, entry) @mutex.synchronize do (@data[unit.to_s] ||= {})[exp] = entry end nil end |