Skip to content

Commit 12f53ef

Browse files
committed
removed recordCache store
1 parent ecf3524 commit 12f53ef

File tree

3 files changed

+6
-50
lines changed

3 files changed

+6
-50
lines changed

api/handlers/handlers.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
)
1515

1616
var QueryStore *cache.Cache
17-
var RecordStore *cache.Cache
1817
var ObjectStore *cache.Cache
1918

2019
func GetHandlers(cfg *config.Config) *http.ServeMux {
@@ -38,10 +37,6 @@ func GetCacheOptions(cfg *config.Config, values []interface{}) *graphcache.Graph
3837
qs := GetNewCacheStore(cfg)
3938
QueryStore = &qs
4039
}
41-
if RecordStore == nil {
42-
rs := GetNewCacheStore(cfg)
43-
RecordStore = &rs
44-
}
4540
if ObjectStore == nil {
4641
os := GetNewCacheStore(cfg)
4742
ObjectStore = &os
@@ -54,7 +49,6 @@ func GetCacheOptions(cfg *config.Config, values []interface{}) *graphcache.Graph
5449
valueHash := base64.StdEncoding.EncodeToString([]byte(strings.Join(valueStr, "::")))
5550

5651
return &graphcache.GraphCacheOptions{
57-
RecordStore: *RecordStore,
5852
QueryStore: *QueryStore,
5953
ObjectStore: *ObjectStore,
6054
Prefix: valueHash,

graphcache/graphcache.go

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ const DEFAULT_CACHE_PREFIX = "orbit::"
1717

1818
// GraphCache is a struct that holds the cache stores for the GraphQL cache
1919
type GraphCache struct {
20-
prefix string
21-
cacheStore cache.Cache
22-
recordCacheStore cache.Cache
23-
queryCacheStore cache.Cache
20+
prefix string
21+
cacheStore cache.Cache
22+
queryCacheStore cache.Cache
2423
}
2524
type GraphCacheOptions struct {
2625
QueryStore cache.Cache
2726
ObjectStore cache.Cache
28-
RecordStore cache.Cache
2927
Prefix string
3028
}
3129

@@ -37,17 +35,15 @@ const CacheBackendInMemory CacheBackend = "in_memory"
3735
func NewGraphCache() *GraphCache {
3836
return NewGraphCacheWithOptions(&GraphCacheOptions{
3937
ObjectStore: cache.NewInMemoryCache(),
40-
RecordStore: cache.NewInMemoryCache(),
4138
QueryStore: cache.NewInMemoryCache(),
4239
})
4340
}
4441

4542
func NewGraphCacheWithOptions(opts *GraphCacheOptions) *GraphCache {
4643
return &GraphCache{
47-
prefix: opts.Prefix,
48-
cacheStore: opts.ObjectStore,
49-
recordCacheStore: opts.RecordStore,
50-
queryCacheStore: opts.QueryStore,
44+
prefix: opts.Prefix,
45+
cacheStore: opts.ObjectStore,
46+
queryCacheStore: opts.QueryStore,
5147
}
5248
}
5349

@@ -325,22 +321,12 @@ func (gc *GraphCache) CacheObject(field string, object map[string]interface{}, p
325321
id := object["id"].(string)
326322
cacheKey := typename + ":" + id
327323
gc.cacheStore.Set(gc.Key(cacheKey), object)
328-
329-
for key, value := range object {
330-
gc.recordCacheStore.Set(gc.Key(cacheKey+":"+key), value)
331-
}
332-
333324
return gc.Key(cacheKey)
334325
} else if utils.StringArrayContainsString(objectKeys, "__typename") && !utils.StringArrayContainsString(objectKeys, "id") && parent != nil && utils.StringArrayContainsString(parentKeys, "id") && utils.StringArrayContainsString(parentKeys, "__typename") {
335326
typename := parent["__typename"].(string)
336327
parentID := parent["id"].(string)
337328
cacheKey := typename + ":" + parentID + ":" + field
338329
gc.cacheStore.Set(gc.Key(cacheKey), object)
339-
340-
for key, value := range object {
341-
gc.recordCacheStore.Set(gc.Key(cacheKey+":"+key), value)
342-
}
343-
344330
return gc.Key(cacheKey)
345331
}
346332

@@ -571,22 +557,12 @@ func (gc *GraphCache) InvalidateCacheObject(field string, object map[string]inte
571557
id := object["id"].(string)
572558
cacheKey := typename + ":" + id
573559
gc.cacheStore.DeleteByPrefix(gc.Key(cacheKey))
574-
575-
for key := range object {
576-
gc.recordCacheStore.Del(gc.Key(cacheKey + ":" + key))
577-
}
578-
579560
return gc.Key(cacheKey)
580561
} else if utils.StringArrayContainsString(objectKeys, "__typename") && !utils.StringArrayContainsString(objectKeys, "id") && parent != nil && utils.StringArrayContainsString(parentKeys, "id") && utils.StringArrayContainsString(parentKeys, "__typename") {
581562
typename := parent["__typename"].(string)
582563
parentID := parent["id"].(string)
583564
cacheKey := typename + ":" + parentID + ":" + field
584565
gc.cacheStore.DeleteByPrefix(gc.Key(cacheKey))
585-
586-
for key := range object {
587-
gc.recordCacheStore.Del(gc.Key(cacheKey + ":" + key))
588-
}
589-
590566
return gc.Key(cacheKey)
591567
}
592568

@@ -595,31 +571,26 @@ func (gc *GraphCache) InvalidateCacheObject(field string, object map[string]inte
595571

596572
func (gc *GraphCache) Debug() {
597573
gc.cacheStore.Debug("cacheStore")
598-
gc.recordCacheStore.Debug("recordCacheStore")
599574
gc.queryCacheStore.Debug("queryCacheStore")
600575
}
601576

602577
func (gc *GraphCache) Look() map[string]interface{} {
603578
output := make(map[string]interface{})
604579
cacheMap, _ := gc.cacheStore.Map()
605-
recordCacheMap, _ := gc.recordCacheStore.Map()
606580
queryCacheMap, _ := gc.queryCacheStore.Map()
607581

608582
output["cacheStore"] = cacheMap
609-
output["recordCacheStore"] = recordCacheMap
610583
output["queryCacheStore"] = queryCacheMap
611584

612585
return output
613586
}
614587

615588
func (gc *GraphCache) Flush() {
616589
gc.cacheStore.Flush()
617-
gc.recordCacheStore.Flush()
618590
gc.queryCacheStore.Flush()
619591
}
620592

621593
func (gc *GraphCache) FlushByType(typeName string, id string) {
622594
gc.cacheStore.DeleteByPrefix(gc.Key(typeName + ":" + id))
623-
gc.recordCacheStore.DeleteByPrefix(gc.Key(typeName + ":" + id))
624595
gc.queryCacheStore.DeleteByPrefix(gc.Key(typeName + ":" + id))
625596
}

main_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -326,21 +326,12 @@ func TestGraphCacheScopeHeaders(t *testing.T) {
326326
user, headers, _, err := client.GetUserByID(userID)
327327
assert.NotNil(t, user)
328328
assert.Nil(t, err)
329-
fmt.Println(headers)
330329
assert.Equal(t, "MISS", headers["X-Orbit-Cache"])
331330

332-
// for i := 0; i < 10; i++ {
333-
// // get the user multiple times
334-
// client.GetUserByID(userID)
335-
// fmt.Println(headers)
336-
// time.Sleep(1 * time.Second)
337-
// }
338-
339331
// get the user again
340332
user, headers, _, err = client.GetUserByID(userID)
341333
assert.NotNil(t, user)
342334
assert.Nil(t, err)
343-
fmt.Println(headers)
344335
assert.Equal(t, "HIT", headers["X-Orbit-Cache"])
345336

346337
// create a new client with a different authorization header

0 commit comments

Comments
 (0)