-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.go
More file actions
42 lines (30 loc) · 835 Bytes
/
cache.go
File metadata and controls
42 lines (30 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package simplecache
/*
* @Author: ZhenpengDeng(monitor1379)
* @Date: 2020-05-27 13:53:35
* @Last Modified by: ZhenpengDeng(monitor1379)
* @Last Modified time: 2020-05-27 22:06:59
*/
import "time"
type Cache interface {
// size 是一个字符串。支持以下参数: 1KB, 100KB, 1MB, 2MB, 1GB 等
SetMaxMemory(size string) error
// 设置一个缓存项,并且在expire时间之后过期
Set(key string, value interface{}, expire time.Duration) error
// 获取一个值
Get(key string) (interface{}, bool)
// 删除一个值
Del(key string) bool
// 检测一个值是否存在
Exists(key string) bool
// 清空所有值
Flush() error
// 返回key的数量
Keys() int64
}
func New() Cache {
return NewMemCache()
}
func NewWithOptions(options Options) Cache {
return NewMemCacheWithOptions(options)
}