-
Notifications
You must be signed in to change notification settings - Fork 0
/
in_memory_map.go
33 lines (27 loc) · 920 Bytes
/
in_memory_map.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
package imagesearchfscache
import (
"github.com/jamesrr39/image-search-app/imagesearch"
"sync"
)
type imageSearchCacheMap struct {
mu *sync.Mutex
m map[string]*imagesearch.PersistedImageDescriptor
}
func newImageSearchCacheMap() *imageSearchCacheMap {
return &imageSearchCacheMap{new(sync.Mutex), make(map[string]*imagesearch.PersistedImageDescriptor)}
}
func (cacheMap *imageSearchCacheMap) Add(id string, descriptor *imagesearch.PersistedImageDescriptor) {
cacheMap.mu.Lock()
cacheMap.m[id] = descriptor
cacheMap.mu.Unlock()
}
func (cacheMap *imageSearchCacheMap) Get(id string) *imagesearch.PersistedImageDescriptor {
return cacheMap.m[id]
}
func (cacheMap *imageSearchCacheMap) GetAll() []*imagesearch.PersistedImageDescriptor {
var descriptors []*imagesearch.PersistedImageDescriptor
for _, descriptor := range cacheMap.m {
descriptors = append(descriptors, descriptor)
}
return descriptors
}