|
|
@ -127,13 +127,13 @@ func (r *Cache) Set(key string, value []byte) bool { |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
// remove random key if only we reach the maxSize threshold
|
|
|
|
// remove random key if only we reach the maxSize threshold
|
|
|
|
for key := range r.items { |
|
|
|
|
|
|
|
for (r.currentSize + valueLen) > r.maxSize { |
|
|
|
for (r.currentSize + valueLen) > r.maxSize { |
|
|
|
|
|
|
|
for key := range r.items { |
|
|
|
r.doDelete(key) |
|
|
|
r.doDelete(key) |
|
|
|
} |
|
|
|
|
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
r.items[key] = value |
|
|
|
r.items[key] = value |
|
|
|
r.currentSize += valueLen |
|
|
|
r.currentSize += valueLen |
|
|
|
r.updatedAt[key] = time.Now() |
|
|
|
r.updatedAt[key] = time.Now() |
|
|
|