Skip to content

Commit 79ed83b

Browse files
committed
Fixes #40 - Make sure inMemoryCache work on Go versions before 1.9
1 parent 4c71c4e commit 79ed83b

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
language: go
22

33
go:
4+
- 1.8
45
- 1.x
56

67
install:
78
- go get -u github.com/golang/dep/...
89
- dep ensure
9-
10-
script:
10+
11+
script:
1112
- go test -v -race -coverprofile=coverage.txt -covermode=atomic
1213

1314
after_success:

inMemoryCache.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type InMemoryCache struct {
1919

2020
// NewCache constructs a new InMemoryCache
2121
func NewCache() *InMemoryCache {
22-
items := make(map[interface{}]Thunk)
22+
items := make(map[string]Thunk)
2323
return &InMemoryCache{
2424
items: items,
2525
}
@@ -28,7 +28,7 @@ func NewCache() *InMemoryCache {
2828
// Set sets the `value` at `key` in the cache
2929
func (c *InMemoryCache) Set(_ context.Context, key Key, value Thunk) {
3030
c.mu.Lock()
31-
c.items[key.Key()] = value
31+
c.items[key.String()] = value
3232
c.mu.Unlock()
3333
}
3434

@@ -38,7 +38,7 @@ func (c *InMemoryCache) Get(_ context.Context, key Key) (Thunk, bool) {
3838
c.mu.RLock()
3939
defer c.mu.RUnlock()
4040

41-
item, found := c.items[key.Key()]
41+
item, found := c.items[key.String()]
4242
if !found {
4343
return nil, false
4444
}
@@ -47,11 +47,11 @@ func (c *InMemoryCache) Get(_ context.Context, key Key) (Thunk, bool) {
4747
}
4848

4949
// Delete deletes item at `key` from cache
50-
func (c *InMemoryCache) Delete(ctx context.Context, key interface{}) bool {
50+
func (c *InMemoryCache) Delete(ctx context.Context, key Key) bool {
5151
if _, found := c.Get(ctx, key); found {
5252
c.mu.Lock()
5353
defer c.mu.Unlock()
54-
delete(c.items, key.Key())
54+
delete(c.items, key.String())
5555
return true
5656
}
5757
return false

0 commit comments

Comments
 (0)