Cache support

Updated at:

PAI-Rec supports two caching methods: local cache (go-cache) and Redis.

For the local cache, defaultExpiration sets the default key expiration time, and cleanupInterval sets the interval for removing expired keys. Both values are in seconds.

config := "{\"defaultExpiration\":1800, \"cleanupInterval\":1800}"
cache, err := NewCache("localCache", config)

Using Redis:

config := "{\"host\":\"127.0.0.1\", \"port\":6379, \"maxIdle\":3, \"password\":\"\"}"

cache, err := NewCache("redis", config)

The cache interface is defined as follows:

type Cache interface {
    Put(key string, val interface{}, duration time.Duration) error
    Get(key string) interface{}
    DefaultGet(key string, defaultValue interface{}) interface{}
    Delete(key string) error
    StartAndGC(config string) error
}