-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcache.go
46 lines (38 loc) · 787 Bytes
/
cache.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
package main
import (
"fmt"
"github.com/shurcooL/graphql"
)
type sceneCache struct {
scenes map[string]*Scene
client *graphql.Client
}
func newSceneCache(client *graphql.Client) *sceneCache {
return &sceneCache{
scenes: make(map[string]*Scene),
client: client,
}
}
func (c *sceneCache) get(hash string) (*Scene, error) {
if c.scenes[hash] != nil {
return c.scenes[hash], nil
}
var ret *Scene
var err error
if len(hash) == 32 {
ret, err = findSceneFromChecksum(c.client, hash)
if err != nil {
return nil, err
}
} else if len(hash) == 16 {
ret, err = findSceneFromOshash(c.client, hash)
if err != nil {
return nil, err
}
}
if ret == nil {
return nil, fmt.Errorf("scene with hash %s is nil", hash)
}
c.scenes[hash] = ret
return ret, nil
}