-
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathcache.go
More file actions
35 lines (28 loc) · 583 Bytes
/
Copy pathcache.go
File metadata and controls
35 lines (28 loc) · 583 Bytes
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
package deck
import (
"sync"
)
var globalCache = &cache{
mu: sync.RWMutex{},
m: make(map[string]*internalImage),
}
type cache struct {
mu sync.RWMutex
m map[string]*internalImage
}
func LoadImageCache(key string) (*Image, bool) {
globalCache.mu.RLock()
defer globalCache.mu.RUnlock()
if v, ok := globalCache.m[key]; ok {
var img Image
if err := v.toImage(&img); err == nil {
return &img, true
}
}
return nil, false
}
func StoreImageCache(key string, i *Image) {
globalCache.mu.Lock()
defer globalCache.mu.Unlock()
globalCache.m[key] = i.toInternal()
}