-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcache.go
31 lines (27 loc) · 1.06 KB
/
cache.go
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
package gocache
import (
"github.com/hunterhug/gocache/algorithm"
"time"
)
type Cache interface {
Set(key string, value []byte, expireTime time.Duration)
SetInterface(key string, value interface{}, expireTime time.Duration)
SetByExpireUnixNanosecondDateTime(key string, value []byte, expireUnixNanosecondDateTime int64)
SetInterfaceByExpireUnixNanosecondDateTime(key string, value interface{}, expireUnixNanosecondDateTime int64)
Delete(key string)
Get(key string) (value []byte, expireUnixNanosecondDateTime int64, exist bool)
GetInterface(key string) (value interface{}, expireUnixNanosecondDateTime int64, exist bool)
GetOldestKey() (key string, expireUnixNanosecondDateTime int64, exist bool)
Size() int
Index(index int) (value []byte, expireUnixNanosecondDateTime int64, exist bool)
IndexInterface(index int) (value interface{}, expireUnixNanosecondDateTime int64, exist bool)
KeyList() []string
ShutDown()
}
func New() Cache {
c := new(cache)
c.treeMap = algorithm.NewTreeMap()
c.minHeap = algorithm.NewMinHeap(nil)
go c.loopCleanExpireItem()
return c
}