diff options
author | Santiago M. Mola <santi@mola.io> | 2017-07-24 13:36:41 +0200 |
---|---|---|
committer | Santiago M. Mola <santi@mola.io> | 2017-07-27 14:15:09 +0200 |
commit | f07672f5c3cad2e73596ab3d7ca16660f6881df6 (patch) | |
tree | c3e6162aacf6ee1c38bd3a3915dcb040b5006627 /plumbing/cache/object.go | |
parent | 854ffa16f650706200a6ebb5505bb448b5c64035 (diff) | |
download | go-git-f07672f5c3cad2e73596ab3d7ca16660f6881df6.tar.gz |
plumbing/cache: use more explicit interface
* renamed Add to Put
* Get returns a second bool value to indicate if there
was hit or miss.
Diffstat (limited to 'plumbing/cache/object.go')
-rw-r--r-- | plumbing/cache/object.go | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/plumbing/cache/object.go b/plumbing/cache/object.go index 44238ce..44e0d32 100644 --- a/plumbing/cache/object.go +++ b/plumbing/cache/object.go @@ -1,6 +1,8 @@ package cache -import "gopkg.in/src-d/go-git.v4/plumbing" +import ( + "gopkg.in/src-d/go-git.v4/plumbing" +) const ( initialQueueSize = 20 @@ -25,12 +27,14 @@ func NewObjectFIFO(size FileSize) *ObjectFIFO { } } -// Add adds a new object to the cache. If the object size is greater than the +// Put puts a new object to the cache. If the object size is greater than the // cache size, the object is not added. -func (c *ObjectFIFO) Add(o plumbing.EncodedObject) { +func (c *ObjectFIFO) Put(o plumbing.EncodedObject) { + objSize := FileSize(o.Size()) + // if the size of the object is bigger or equal than the cache size, // skip it - if FileSize(o.Size()) >= c.maxSize { + if objSize >= c.maxSize { return } @@ -56,8 +60,9 @@ func (c *ObjectFIFO) Add(o plumbing.EncodedObject) { // Get returns an object by his hash. If the object is not found in the cache, it // returns nil -func (c *ObjectFIFO) Get(k plumbing.Hash) plumbing.EncodedObject { - return c.objects[k] +func (c *ObjectFIFO) Get(k plumbing.Hash) (plumbing.EncodedObject, bool) { + obj, ok := c.objects[k] + return obj, ok } // Clear the content of this object cache |