Skip to content

Commit a7ede83

Browse files
authored
Merge pull request #84 from graph-gophers/add-generics-support
Upgrade to Go v1.18 and add support for generics
2 parents 480116a + b7b6fed commit a7ede83

File tree

16 files changed

+513
-396
lines changed

16 files changed

+513
-396
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
language: go
22

33
go:
4-
- 1.16
5-
- 1.15
6-
- 1.14
4+
- 1.18
75

86
env:
97
- GO111MODULE=on

cache.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ package dataloader
33
import "context"
44

55
// The Cache interface. If a custom cache is provided, it must implement this interface.
6-
type Cache interface {
7-
Get(context.Context, Key) (Thunk, bool)
8-
Set(context.Context, Key, Thunk)
9-
Delete(context.Context, Key) bool
6+
type Cache[K comparable, V any] interface {
7+
Get(context.Context, K) (Thunk[V], bool)
8+
Set(context.Context, K, Thunk[V])
9+
Delete(context.Context, K) bool
1010
Clear()
1111
}
1212

1313
// NoCache implements Cache interface where all methods are noops.
1414
// This is useful for when you don't want to cache items but still
1515
// want to use a data loader
16-
type NoCache struct{}
16+
type NoCache[K comparable, V any] struct{}
1717

1818
// Get is a NOOP
19-
func (c *NoCache) Get(context.Context, Key) (Thunk, bool) { return nil, false }
19+
func (c *NoCache[K, V]) Get(context.Context, K) (Thunk[V], bool) { return nil, false }
2020

2121
// Set is a NOOP
22-
func (c *NoCache) Set(context.Context, Key, Thunk) { return }
22+
func (c *NoCache[K, V]) Set(context.Context, K, Thunk[V]) { return }
2323

2424
// Delete is a NOOP
25-
func (c *NoCache) Delete(context.Context, Key) bool { return false }
25+
func (c *NoCache[K, V]) Delete(context.Context, K) bool { return false }
2626

2727
// Clear is a NOOP
28-
func (c *NoCache) Clear() { return }
28+
func (c *NoCache[K, V]) Clear() { return }

0 commit comments

Comments
 (0)