文档

缓存支持

pairec 目前提供了两种缓存方式,本地缓存(go-cache) 和 redis。

使用本地缓存, defaultExpiration 是 key 默认的过期时间,cleanupInterval 是清理 key 的时间间隔,单位都是秒

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

使用 redis

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

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

cache 的接口如下定义

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
}
  • 本页导读 (0)
文档反馈