Merge branch 'upstream-mirror' into sync-updates
# Conflicts: # layeredcache_test.go
This commit is contained in:
11
cache.go
11
cache.go
@@ -141,6 +141,9 @@ func (c *Cache) Replace(key string, value interface{}) bool {
|
||||
// Attempts to get the value from the cache and calles fetch on a miss (missing
|
||||
// or stale item). If fetch returns an error, no value is cached and the error
|
||||
// is returned back to the caller.
|
||||
// Note that Fetch merely calls the public Get and Set functions. If you want
|
||||
// a different Fetch behavior, such as thundering herd protection or returning
|
||||
// expired items, implement it in your application.
|
||||
func (c *Cache) Fetch(key string, duration time.Duration, fetch func() (interface{}, error)) (*Item, error) {
|
||||
item := c.Get(key)
|
||||
if item != nil && !item.Expired() {
|
||||
@@ -373,7 +376,13 @@ func (c *Cache) doPromote(item *Item) bool {
|
||||
func (c *Cache) gc() int {
|
||||
dropped := 0
|
||||
element := c.list.Back()
|
||||
for i := 0; i < c.itemsToPrune; i++ {
|
||||
|
||||
itemsToPrune := int64(c.itemsToPrune)
|
||||
if min := c.size - c.maxSize; min > itemsToPrune {
|
||||
itemsToPrune = min
|
||||
}
|
||||
|
||||
for i := int64(0); i < itemsToPrune; i++ {
|
||||
if element == nil {
|
||||
return dropped
|
||||
}
|
||||
|
Reference in New Issue
Block a user