-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
36 lines (31 loc) · 886 Bytes
/
store.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
32
33
34
35
36
package store
import (
"time"
)
// Store provides a interface to implement cache stores.
type Store interface {
Flush() error
// Decrement(string, ...int64) (int64, error)
Get(string) (interface{}, error)
// Number(string) (int64, error)
// Increment(string, ...int64) (int64, error)
// Remember(string, time.Duration, RememberFunc) (interface{}, error)
Remove(string) error
Result(string, interface{}) error
Set(string, interface{}, time.Duration) error
Close() error
}
// RememberFunc is the function that is used for remember method.
type RememberFunc func() interface{}
// Item represents a item in the cache.
type Item struct {
Expiration time.Duration
Object interface{}
}
// Expired returns true if the item has expired.
func (item Item) Expired() bool {
if item.Expiration == 0 {
return false
}
return time.Now().UnixNano() > int64(item.Expiration)
}