Skip to content

Commit

Permalink
Fixes #40 - Make sure inMemoryCache work on Go versions before 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksrandall committed May 18, 2018
1 parent 4c71c4e commit 79ed83b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
@@ -1,13 +1,14 @@
language: go

go:
- 1.8
- 1.x

install:
- go get -u github.com/golang/dep/...
- dep ensure
script:

script:
- go test -v -race -coverprofile=coverage.txt -covermode=atomic

after_success:
Expand Down
10 changes: 5 additions & 5 deletions inMemoryCache.go
Expand Up @@ -19,7 +19,7 @@ type InMemoryCache struct {

// NewCache constructs a new InMemoryCache
func NewCache() *InMemoryCache {
items := make(map[interface{}]Thunk)
items := make(map[string]Thunk)
return &InMemoryCache{
items: items,
}
Expand All @@ -28,7 +28,7 @@ func NewCache() *InMemoryCache {
// Set sets the `value` at `key` in the cache
func (c *InMemoryCache) Set(_ context.Context, key Key, value Thunk) {
c.mu.Lock()
c.items[key.Key()] = value
c.items[key.String()] = value
c.mu.Unlock()
}

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

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

// Delete deletes item at `key` from cache
func (c *InMemoryCache) Delete(ctx context.Context, key interface{}) bool {
func (c *InMemoryCache) Delete(ctx context.Context, key Key) bool {
if _, found := c.Get(ctx, key); found {
c.mu.Lock()
defer c.mu.Unlock()
delete(c.items, key.Key())
delete(c.items, key.String())
return true
}
return false
Expand Down

0 comments on commit 79ed83b

Please sign in to comment.