-
Notifications
You must be signed in to change notification settings - Fork 2
/
apiextensions.go
38 lines (34 loc) · 987 Bytes
/
apiextensions.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
package testapi
import (
"errors"
)
type CacheStats struct {
AssetCount int
ContentTypes []string
EntryCount int
ParentCount int
}
func (cc *ContentfulClient) GetCacheStats() (*CacheStats, error) {
if cc == nil {
return nil, errors.New("GetCacheStats: no client available")
}
return &CacheStats{
AssetCount: len(cc.Cache.assets),
ContentTypes: cc.Cache.contentTypes,
EntryCount: len(cc.Cache.idContentTypeMap),
ParentCount: len(cc.Cache.parentMap),
}, nil
}
func (cc *ContentfulClient) SetProductInCache(product *CfProduct) {
if cc.Cache == nil {
return
}
cc.cacheMutex.productGcLock.Lock()
defer cc.cacheMutex.productGcLock.Unlock()
cc.cacheMutex.idContentTypeMapGcLock.Lock()
defer cc.cacheMutex.idContentTypeMapGcLock.Unlock()
cc.cacheMutex.parentMapGcLock.Lock()
defer cc.cacheMutex.parentMapGcLock.Unlock()
cc.Cache.entryMaps.product[product.Sys.ID] = product
cc.Cache.idContentTypeMap[product.Sys.ID] = product.Sys.ContentType.Sys.ID
}