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 a Storage Service

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

Usage

class StorageConnector extends StorageConnector {
  constructor() {
    super();
  }

  /**
   * Get data from storage
   * @param {string} featureKey
   * @param {string} userId
   * @returns {Promise<any>}
   */
  async get(featureKey, userId) {
    // return await data (based on featureKey and userId)
  }

  /**
   * Set data in storage
   * @param {object} data
   */
  async set(data) {
    // Set data corresponding to a featureKey and user ID
    // Use data.featureKey and data.userId to store the above data for a specific feature and a user
  }
}

vwo.init({
  sdkKey: '...',
  accountId: '123456',
  storage: StorageConnector,
});

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

Method NameParamsDescriptionReturns
getfeatureKey, userIdRetrieve stored data corresponding to featureKey and userIdReturns a matching user-feature data mapping corresponding to featureKey and userId passed
setdataStore user-feature data mappingnull

What’s Next