...
1 package graphql
2
3 import "context"
4
5
6 type Cache interface {
7
8 Get(ctx context.Context, key string) (value interface{}, ok bool)
9
10
11 Add(ctx context.Context, key string, value interface{})
12 }
13
14
15 type MapCache map[string]interface{}
16
17
18 func (m MapCache) Get(_ context.Context, key string) (value interface{}, ok bool) {
19 v, ok := m[key]
20 return v, ok
21 }
22
23
24 func (m MapCache) Add(_ context.Context, key string, value interface{}) { m[key] = value }
25
26 type NoCache struct{}
27
28 func (n NoCache) Get(_ context.Context, _ string) (value interface{}, ok bool) { return nil, false }
29 func (n NoCache) Add(_ context.Context, _ string, _ interface{}) {}
30
View as plain text