replace is size-aware

This commit is contained in:
Karl Seguin
2014-11-21 15:45:11 +07:00
parent 41ccfbb39a
commit 78e597cdae
6 changed files with 72 additions and 9 deletions

View File

@@ -82,7 +82,11 @@ func (c *Cache) Set(key string, value interface{}, duration time.Duration) {
// Returns true if the item existed an was replaced, false otherwise.
// Replace does not reset item's TTL nor does it alter its position in the LRU
func (c *Cache) Replace(key string, value interface{}) bool {
return c.bucket(key).replace(key, value)
exists, d := c.bucket(key).replace(key, value)
if d != 0 {
atomic.AddInt64(&c.size, d)
}
return exists
}
// Attempts to get the value from the cache and calles fetch on a miss.