Provides 2 out of the box ODP cache including in-memory and redis.
in-memory will use the builtin LRU cache with user provided size and timeout.
Adds support for custom odp cache.
If no odp cache is provided, agent will use go-sdk's in built LRU Cache with default size and timeout.
Out of Box ODP Cache Usage
To use the in-memory ODPCache, update the config.yaml as shown below:
## configure optional ODP Cache
odp:
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 the config.yaml as shown below:
Update the config.yaml file with your ODPCache config 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 ODPCache services and wants to override the defaultODPCache for a specific sdkKey, they can do so by providing the ODPCache name in the request Header X-Optimizely-ODP-Cache-Name.
Whenever a request is made with a unique sdkKey, The agent node handling that request creates and caches a new ODPCache. To keep the ODPCache type consistent among all nodes in a cluster, it is recommended to send the request Header X-Optimizely-ODP-Cache-Name in every request made.
Summary
in-memory
andredis
.in-memory
will use the builtin LRU cache with user providedsize
andtimeout
.size
andtimeout
.Out of Box ODP Cache Usage
To use the in-memory
ODPCache
, update theconfig.yaml
as shown below:To use the redis
ODPCache
, update theconfig.yaml
as shown below:Custom ODPCache Implementation
To implement a custom odp cache, followings steps need to be taken:
cache.Cache
interface inplugins/odpcache/services
.init
method inside your ODPCache file as shown below:config.yaml
file with yourODPCache
config as shown below:If a user has created multiple
ODPCache
services and wants to override thedefault
ODPCache
for a specificsdkKey
, they can do so by providing theODPCache
name 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 theODPCache
type consistent among all nodes in a cluster, it is recommended to send the request HeaderX-Optimizely-ODP-Cache-Name
in every request made.Tests
Ticket
FSSDK-8838