Vendored
+34
@@ -0,0 +1,34 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
cache "github.com/robfig/go-cache"
|
||||
)
|
||||
|
||||
// Cache 服务单机本地缓存
|
||||
type Cache struct {
|
||||
Expiration time.Duration
|
||||
CleanInterval time.Duration
|
||||
Cli *cache.Cache
|
||||
}
|
||||
|
||||
// New 创建缓存客户端
|
||||
func (c *Cache) New() {
|
||||
c.Cli = cache.New(c.Expiration, c.CleanInterval)
|
||||
}
|
||||
|
||||
// Set 设置键值
|
||||
func (c *Cache) Set(key string, value interface{}, expiration time.Duration) {
|
||||
c.Cli.Set(key, value, expiration)
|
||||
}
|
||||
|
||||
// Get 获取值
|
||||
func (c *Cache) Get(key string) (result interface{}, exists bool) {
|
||||
return c.Cli.Get(key)
|
||||
}
|
||||
|
||||
// Add 添加值
|
||||
func (c *Cache) Add(key string, value interface{}, expiration time.Duration) error {
|
||||
return c.Cli.Add(key, value, expiration)
|
||||
}
|
||||
Reference in New Issue
Block a user