forked from NubeDev/bacnet
/
init.go
33 lines (27 loc) · 828 Bytes
/
init.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
package store
import (
"github.com/patrickmn/go-cache"
"time"
)
//var store *cache.Cache
type Handler struct {
Store *cache.Cache
}
//Init init store
func Init() *Handler {
newStore := cache.New(cache.NoExpiration, cache.DefaultExpiration)
store := &Handler{Store: newStore}
return store
}
// Get an item from the store. Returns the item or nil, and a bool indicating
// whether the key was found.
func (l *Handler) Get(key string) (interface{}, bool) {
value, found := l.Store.Get(key)
return value, found
}
// Set an item to the store, replacing any existing item. If the duration is 0
// (DefaultExpiration), the store's default expiration time is used. If it is -1
// (NoExpiration), the item never expires.
func (l *Handler) Set(key string, value interface{}, d time.Duration) {
l.Store.Set(key, value, d)
}