aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/cache
diff options
context:
space:
mode:
authorJavi Fontan <jfontan@gmail.com>2017-12-20 15:11:38 +0100
committerJavi Fontan <jfontan@gmail.com>2017-12-20 15:27:45 +0100
commit962eeb399ce322daa4dd6522cdc91d277fbdba2c (patch)
tree3cfccb1568290dcb0db44cfa94f40b9b012d870f /plumbing/cache
parent55b5d736682bf0e251c5bf83d1cf25c298d3ea0c (diff)
downloadgo-git-962eeb399ce322daa4dd6522cdc91d277fbdba2c.tar.gz
Enforce the use of cache in packfile decoder
Decoder object can make use of an object cache to speed up processing. Previously the only way to specify it was changing manually the struct generated by NewDecodeForFile. This lead to some instances to be created without it and penalized performance. Now the cache should be explicitly passed to the constructor function. NewDecoder now creates objects with a cache using the default size. A new helper function was added to create cache objects with the default size as this becomes a common task now: cache.NewObjectLRUDefault() Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'plumbing/cache')
-rw-r--r--plumbing/cache/common.go2
-rw-r--r--plumbing/cache/object_lru.go5
2 files changed, 7 insertions, 0 deletions
diff --git a/plumbing/cache/common.go b/plumbing/cache/common.go
index 9efc26c..e77baf0 100644
--- a/plumbing/cache/common.go
+++ b/plumbing/cache/common.go
@@ -11,6 +11,8 @@ const (
type FileSize int64
+const DefaultMaxSize FileSize = 96 * MiByte
+
// Object is an interface to a object cache.
type Object interface {
// Put puts the given object into the cache. Whether this object will
diff --git a/plumbing/cache/object_lru.go b/plumbing/cache/object_lru.go
index e8414ab..d99a5c9 100644
--- a/plumbing/cache/object_lru.go
+++ b/plumbing/cache/object_lru.go
@@ -24,6 +24,11 @@ func NewObjectLRU(maxSize FileSize) *ObjectLRU {
return &ObjectLRU{MaxSize: maxSize}
}
+// NewObjectLRUDefault creates a new ObjectLRU with the default cache size.
+func NewObjectLRUDefault() *ObjectLRU {
+ return &ObjectLRU{MaxSize: DefaultMaxSize}
+}
+
// Put puts an object into the cache. If the object is already in the cache, it
// will be marked as used. Otherwise, it will be inserted. A single object might
// be evicted to make room for the new object.