aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/cache/common.go
diff options
context:
space:
mode:
authorJavi Fontan <jfontan@gmail.com>2018-08-14 11:59:11 +0200
committerJavi Fontan <jfontan@gmail.com>2018-08-14 13:24:51 +0200
commita8c4426d204f42e683e902dcb277494004d5e59d (patch)
treecdfe5c3ca9ee85931474f589120eb9a453085bab /plumbing/cache/common.go
parenta28c2ce44695f13ddf28748958f236afd8e0b544 (diff)
downloadgo-git-a8c4426d204f42e683e902dcb277494004d5e59d.tar.gz
plumbing: add buffer cache and use it in packfile parser
It uses less memory and is faster as slices don't have to be converted from/to MemoryObject and they are indexed by offset. Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'plumbing/cache/common.go')
-rw-r--r--plumbing/cache/common.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/plumbing/cache/common.go b/plumbing/cache/common.go
index e77baf0..2b7f36a 100644
--- a/plumbing/cache/common.go
+++ b/plumbing/cache/common.go
@@ -24,3 +24,16 @@ type Object interface {
// Clear clears every object from the cache.
Clear()
}
+
+// Buffer is an interface to a buffer cache.
+type Buffer interface {
+ // Put puts a buffer into the cache. If the buffer is already in the cache,
+ // it will be marked as used. Otherwise, it will be inserted. Buffer might
+ // be evicted to make room for the new one.
+ Put(key int64, slice []byte)
+ // Get returns a buffer by its key. It marks the buffer as used. If the
+ // buffer is not in the cache, (nil, false) will be returned.
+ Get(key int64) ([]byte, bool)
+ // Clear clears every object from the cache.
+ Clear()
+}