-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache_alias.go
47 lines (43 loc) · 1.15 KB
/
cache_alias.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
43
44
45
46
47
package cbytecache
// GetWithUnmarshaller gets entry bytes and apply unmarshal logic.
func (c *Cache) GetWithUnmarshaller(key string, u Unmarshaller) error {
if u == nil {
return ErrNoUnmarshaller
}
b, err := c.Get(key)
if err != nil {
return err
}
return u.Unmarshal(b)
}
// GetToWithUnmarshaller gets entry bytes to dst and apply unmarshal logic.
func (c *Cache) GetToWithUnmarshaller(dst []byte, key string, u Unmarshaller) (err error) {
if u == nil {
return ErrNoUnmarshaller
}
if dst, err = c.GetTo(dst, key); err != nil {
return
}
return u.Unmarshal(dst)
}
// ExtractWithUnmarshaller extracts entry bytes and apply unmarshal logic.
func (c *Cache) ExtractWithUnmarshaller(key string, u Unmarshaller) error {
if u == nil {
return ErrNoUnmarshaller
}
b, err := c.Extract(key)
if err != nil {
return err
}
return u.Unmarshal(b)
}
// ExtractToWithUnmarshaller extracts entry bytes and apply unmarshal logic.
func (c *Cache) ExtractToWithUnmarshaller(dst []byte, key string, u Unmarshaller) (err error) {
if u == nil {
return ErrNoUnmarshaller
}
if dst, err = c.ExtractTo(dst, key); err != nil {
return
}
return u.Unmarshal(dst)
}