forked from gin-contrib/sessions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memcached.go
36 lines (30 loc) · 960 Bytes
/
memcached.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 memcached
import (
"github.com/bradfitz/gomemcache/memcache"
gsm "github.com/bradleypeabody/gorilla-sessions-memcache"
"github.com/changyenh/sessions"
)
type Store interface {
sessions.Store
}
// client: memcache client (github.com/bradfitz/gomemcache/memcache)
// keyPrefix: prefix for the keys we store.
func NewStore(
client *memcache.Client, keyPrefix string, keyPairs ...[]byte,
) Store {
memcacherClient := gsm.NewGoMemcacher(client)
return NewMemcacheStore(memcacherClient, keyPrefix, keyPairs...)
}
// client: memcache client which implements the gsm.Memcacher interface
// keyPrefix: prefix for the keys we store.
func NewMemcacheStore(
client gsm.Memcacher, keyPrefix string, keyPairs ...[]byte,
) Store {
return &store{gsm.NewMemcacherStore(client, keyPrefix, keyPairs...)}
}
type store struct {
*gsm.MemcacheStore
}
func (c *store) Options(options sessions.Options) {
c.MemcacheStore.Options = options.ToGorillaOptions()
}