Skip to content

Commit

Permalink
Merge pull request #84 from graph-gophers/add-generics-support
Browse files Browse the repository at this point in the history
Upgrade to Go v1.18 and add support for generics
  • Loading branch information
pavelnikolov committed Apr 11, 2022
2 parents 480116a + b7b6fed commit a7ede83
Show file tree
Hide file tree
Showing 16 changed files with 513 additions and 396 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
@@ -1,9 +1,7 @@
language: go

go:
- 1.16
- 1.15
- 1.14
- 1.18

env:
- GO111MODULE=on
Expand Down
18 changes: 9 additions & 9 deletions cache.go
Expand Up @@ -3,26 +3,26 @@ package dataloader
import "context"

// The Cache interface. If a custom cache is provided, it must implement this interface.
type Cache interface {
Get(context.Context, Key) (Thunk, bool)
Set(context.Context, Key, Thunk)
Delete(context.Context, Key) bool
type Cache[K comparable, V any] interface {
Get(context.Context, K) (Thunk[V], bool)
Set(context.Context, K, Thunk[V])
Delete(context.Context, K) bool
Clear()
}

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

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

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

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

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

0 comments on commit a7ede83

Please sign in to comment.