-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #994 from 99designs/feat-cache-ctx
Add context.Context to graphql.Cache interface's methods
- Loading branch information
Showing
6 changed files
with
24 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
package graphql | ||
|
||
import "context" | ||
|
||
// Cache is a shared store for APQ and query AST caching | ||
type Cache interface { | ||
// Get looks up a key's value from the cache. | ||
Get(key string) (value interface{}, ok bool) | ||
Get(ctx context.Context, key string) (value interface{}, ok bool) | ||
|
||
// Add adds a value to the cache. | ||
Add(key string, value interface{}) | ||
Add(ctx context.Context, key string, value interface{}) | ||
} | ||
|
||
// MapCache is the simplest implementation of a cache, because it can not evict it should only be used in tests | ||
type MapCache map[string]interface{} | ||
|
||
// Get looks up a key's value from the cache. | ||
func (m MapCache) Get(key string) (value interface{}, ok bool) { | ||
func (m MapCache) Get(ctx context.Context, key string) (value interface{}, ok bool) { | ||
v, ok := m[key] | ||
return v, ok | ||
} | ||
|
||
// Add adds a value to the cache. | ||
func (m MapCache) Add(key string, value interface{}) { m[key] = value } | ||
func (m MapCache) Add(ctx context.Context, key string, value interface{}) { m[key] = value } | ||
|
||
type NoCache struct{} | ||
|
||
func (n NoCache) Get(key string) (value interface{}, ok bool) { return nil, false } | ||
func (n NoCache) Add(key string, value interface{}) {} | ||
func (n NoCache) Get(ctx context.Context, key string) (value interface{}, ok bool) { return nil, false } | ||
func (n NoCache) Add(ctx context.Context, key string, value interface{}) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters