Skip to content

Commit

Permalink
fix regression for 97c4957
Browse files Browse the repository at this point in the history
* No panics during multiple simultaneous access using LoaderFunc
* Cache.get returns raw values, not item struct.
  • Loading branch information
bluele committed Mar 15, 2017
1 parent 78acdfb commit d2f44c6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
7 changes: 3 additions & 4 deletions arc.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (c *ARC) get(key interface{}, onLoad bool) (interface{}, error) {
if !onLoad {
c.stats.IncrHitCount()
}
return item, nil
return item.value, nil
} else {
delete(c.items, key)
c.b1.PushFront(key)
Expand All @@ -186,7 +186,7 @@ func (c *ARC) get(key interface{}, onLoad bool) (interface{}, error) {
if !onLoad {
c.stats.IncrHitCount()
}
return item, nil
return item.value, nil
} else {
delete(c.items, key)
c.t2.Remove(key, elt)
Expand All @@ -204,11 +204,10 @@ func (c *ARC) get(key interface{}, onLoad bool) (interface{}, error) {
}

func (c *ARC) getValue(key interface{}) (interface{}, error) {
it, err := c.get(key, false)
v, err := c.get(key, false)
if err != nil {
return nil, err
}
v := it.(*arcItem).value
if c.deserializeFunc != nil {
return c.deserializeFunc(key, v)
}
Expand Down
5 changes: 2 additions & 3 deletions lfu.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (c *LFUCache) get(key interface{}, onLoad bool) (interface{}, error) {
if !onLoad {
c.stats.IncrHitCount()
}
return item, nil
return item.value, nil
}
c.mu.Lock()
c.removeItem(item)
Expand All @@ -129,11 +129,10 @@ func (c *LFUCache) get(key interface{}, onLoad bool) (interface{}, error) {
}

func (c *LFUCache) getValue(key interface{}) (interface{}, error) {
it, err := c.get(key, false)
v, err := c.get(key, false)
if err != nil {
return nil, err
}
v := it.(*lfuItem).value
if c.deserializeFunc != nil {
return c.deserializeFunc(key, v)
}
Expand Down
5 changes: 2 additions & 3 deletions lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (c *LRUCache) get(key interface{}, onLoad bool) (interface{}, error) {
if !onLoad {
c.stats.IncrHitCount()
}
return it, nil
return it.value, nil
}
c.mu.Lock()
c.removeElement(item)
Expand All @@ -122,11 +122,10 @@ func (c *LRUCache) get(key interface{}, onLoad bool) (interface{}, error) {
}

func (c *LRUCache) getValue(key interface{}) (interface{}, error) {
it, err := c.get(key, false)
v, err := c.get(key, false)
if err != nil {
return nil, err
}
v := it.(*lruItem).value
if c.deserializeFunc != nil {
return c.deserializeFunc(key, v)
}
Expand Down
5 changes: 2 additions & 3 deletions simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (c *SimpleCache) get(key interface{}, onLoad bool) (interface{}, error) {
if !onLoad {
c.stats.IncrHitCount()
}
return item, nil
return item.value, nil
}
c.mu.Lock()
c.remove(key)
Expand All @@ -109,11 +109,10 @@ func (c *SimpleCache) get(key interface{}, onLoad bool) (interface{}, error) {
}

func (c *SimpleCache) getValue(key interface{}) (interface{}, error) {
it, err := c.get(key, false)
v, err := c.get(key, false)
if err != nil {
return nil, err
}
v := it.(*simpleItem).value
if c.deserializeFunc != nil {
return c.deserializeFunc(key, v)
}
Expand Down

0 comments on commit d2f44c6

Please sign in to comment.