Storage Service

Storage Service is a caching layer to persist data about your users. This helps ensure that variation assignment for any user is always consistent even if you update the traffic split or other campaign settings.

You can implement a storage service that reads and saves user-campaign data mapping in backend services such as Redis, Memcache, MongoDB, or any other storage service.

How to Implement Storage Service

Storage Service is optional while instantiating the VWO SDK. However, to ensure sticky variation assignments, we recommend implementing it.

Usage

public function get($featureKey, $userId) {
       $key = $featureKey . '_' . $userId;
       return isset($this->map[$key]) ? $this->map[$key] : null;
   }

   public function set($data) {
       $key = $data['featureKey'] . '_' . $data['user'];
            
       $this->map[$key] = [
           'rolloutId' => $data['rolloutId'],
           'rolloutKey' => $data['rolloutKey'],
           'rolloutVariationId' => $data['rolloutVariationId'],
           'experimentId' => $data['experimentId'],
           'experimentKey' => $data['experimentKey'],
           'experimentVariationId' => $data['experimentVariationId']
       ];
       return true;
   }

Storage Service should expose two methods: get and set. VWO uses these methods whenever there is a need to read or write from the storage service.

Method NameParamsDescriptionReturns
getkeyRetrieve stored dataReturns a matching user-campaign data mapping corresponding to key passed
setkey, dataStore user-campaign data mapping. It has information like user with User ID become part of a campaign having campaign-key as <Campaign_Key> and got the assigned variation <Variation_Name>.Nothing.