aboutsummaryrefslogtreecommitdiffstats
path: root/worker/jmap/cache/session.go
blob: 7126041f3c639c995b89268fa7302a0b8dafcb12 (plain) (blame)
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
package cache

import (
	"git.sr.ht/~rockorager/go-jmap"
)

func (c *JMAPCache) GetSession() (*jmap.Session, error) {
	buf, err := c.get(sessionKey)
	if err != nil {
		return nil, err
	}
	s := new(jmap.Session)
	err = unmarshal(buf, s)
	if err != nil {
		return nil, err
	}
	return s, nil
}

func (c *JMAPCache) PutSession(s *jmap.Session) error {
	buf, err := marshal(s)
	if err != nil {
		return err
	}
	return c.put(sessionKey, buf)
}

func (c *JMAPCache) DeleteSession() error {
	return c.delete(sessionKey)
}

const sessionKey = "session"