forked from phachon/fasthttpsession
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
42 lines (34 loc) · 964 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
37
38
39
40
41
42
package memcache
import (
"github.com/bradfitz/gomemcache/memcache"
"github.com/mikhailzhukov/fasthttpsession"
"github.com/valyala/fasthttp"
)
// session memCache store
// new default memCache store
func NewMemCacheStore(sessionId string) *Store {
memCacheStore := &Store{}
memCacheStore.Init(sessionId, make(map[string]interface{}))
return memCacheStore
}
// new memCache store data
func NewMemCacheStoreData(sessionId string, data map[string]interface{}) *Store {
memCacheStore := &Store{}
memCacheStore.Init(sessionId, data)
return memCacheStore
}
type Store struct {
fasthttpsession.Store
}
// save store
func (mcs *Store) Save(ctx *fasthttp.RequestCtx) error {
value, err := provider.config.SerializeFunc(mcs.GetAll())
if err != nil {
return err
}
return provider.memCacheClient.Set(&memcache.Item{
Key: provider.getMemCacheSessionKey(mcs.GetSessionId()),
Value: value,
Expiration: int32(provider.maxLifeTime),
})
}