From 5b1cde56bde4834805b14f1613e8f7fda1703bf8 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 16 Jan 2018 11:48:12 +0000 Subject: Modify cache to delete more than one item to free space The previous version could only delete the oldest used object. If the object to cache was bigger than the space freed it could not be added. Also the decoder adds bases to the cache when they are needed. This change increases the speed creating indexes 2x. Signed-off-by: Javi Fontan --- plumbing/cache/object_lru.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'plumbing/cache/object_lru.go') diff --git a/plumbing/cache/object_lru.go b/plumbing/cache/object_lru.go index d99a5c9..9e850b2 100644 --- a/plumbing/cache/object_lru.go +++ b/plumbing/cache/object_lru.go @@ -55,7 +55,7 @@ func (c *ObjectLRU) Put(obj plumbing.EncodedObject) { return } - if c.actualSize+objSize > c.MaxSize { + for c.actualSize+objSize > c.MaxSize { last := c.ll.Back() lastObj := last.Value.(plumbing.EncodedObject) lastSize := FileSize(lastObj.Size()) @@ -63,10 +63,6 @@ func (c *ObjectLRU) Put(obj plumbing.EncodedObject) { c.ll.Remove(last) delete(c.cache, lastObj.Hash()) c.actualSize -= lastSize - - if c.actualSize+objSize > c.MaxSize { - return - } } ee := c.ll.PushFront(obj) -- cgit