Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Go v1.18 and add support for generics #84

Merged
merged 1 commit into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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 }
Loading