optimizely / agent

Agent service for Optimizely Feature Experimentation and Optimizely Full Stack (legacy)
Apache License 2.0
31 stars 26 forks source link

[FSSDK-8838] feat(odp-cache): Adds support for odp cache. #365

Closed yasirfolio3 closed 1 year ago

yasirfolio3 commented 1 year ago

Summary

Out of Box ODP Cache Usage

  1. 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
  2. To use the redis ODPCache, update the config.yaml as shown below:

    ## configure optional ODP Cache
    odp:
    segmentsCache:
    default: "redis"
    services:
      redis: 
        host: "your_host"
        password: "your_password"
        database: 0 ## your database
        timeout: 0s

Custom ODPCache Implementation

To implement a custom odp cache, followings steps need to be taken:

  1. Create a struct that implements the cache.Cache interface in plugins/odpcache/services.
  2. Add a init method inside your ODPCache file as shown below:
    func init() {
    myCacheCreator := func() cache.Cache {
        return &yourCacheStruct{
        }
    }
    odpcache.Add("my_cache_name", myCacheCreator)
    }
  3. 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”

Tests

Ticket

FSSDK-8838