Use a ODP Cache to cache user segments fetched from the ODP server.
- To use the in-memory
ODPCache, update theconfig.yamlas shown below:
## configure optional ODP Cache
odp:
## If no segmentsCache is defined (or no default is defined), we will use the default in-memory with default size and timeout
segmentsCache:
default: "in-memory"
services:
in-memory:
## 0 means cache will be disabled
size: 0
## timeout after which the cached item will become invalid.
## 0 means records will never be deleted
timeout: 0s
- To use the redis
ODPCache, update theconfig.yamlas shown below:
## configure optional ODP Cache
odp:
## If no segmentsCache is defined (or no default is defined), we will use the default in-memory with default size and timeout
segmentsCache:
default: "redis"
services:
redis:
host: "your_host"
password: "your_password"
database: 0 ## your database
timeout: 0s
To implement a custom odp cache, followings steps need to be taken:
- Create a struct that implements the
cache.Cacheinterface inplugins/odpcache/services. - Add a
initmethod inside your ODPCache file as shown below:
func init() {
myCacheCreator := func() cache.Cache {
return &yourCacheStruct{
}
}
odpcache.Add("my_cache_name", myCacheCreator)
}
- Update the
config.yamlfile with yourODPCacheconfig as shown below:
## configure optional ODPCache
odp
segmentsCache:
default: "my_cache_name"
services:
my_cache_name:
## Add those parameters here that need to be mapped to the ODPCache
## For example, if the ODP struct has a json mappable property called `host`
## it can updated with value `abc.com` as shown
host: “abc.com”
-
If a user has created multiple
ODPCacheservices and wants to override thedefaultODPCachefor a specificsdkKey, they can do so by providing theODPCachename in the request HeaderX-Optimizely-ODP-Cache-Name. -
Whenever a request is made with a unique
sdkKey, The agent node handling that request creates and caches a newODPCache. To keep theODPCachetype consistent among all nodes in a cluster, it is recommended to send the request HeaderX-Optimizely-ODP-Cache-Namein every request made.