Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit ac7c466

Browse files
committed
Add loose object cache.
Signed-off-by: Filip Navara <[email protected]>
1 parent 65c5695 commit ac7c466

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

storage/filesystem/object.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,24 @@ type ObjectStorage struct {
2323
// deltaBaseCache is an object cache uses to cache delta's bases when
2424
deltaBaseCache cache.Object
2525

26+
simpleObjectCache cache.Object
27+
2628
dir *dotgit.DotGit
2729
index map[plumbing.Hash]idxfile.Index
2830
}
2931

3032
// NewObjectStorage creates a new ObjectStorage with the given .git directory and cache.
31-
func NewObjectStorage(dir *dotgit.DotGit, cache cache.Object) *ObjectStorage {
32-
return NewObjectStorageWithOptions(dir, cache, Options{})
33+
func NewObjectStorage(dir *dotgit.DotGit, deltaBaseCache cache.Object) *ObjectStorage {
34+
return NewObjectStorageWithOptions(dir, deltaBaseCache, Options{})
3335
}
3436

3537
// NewObjectStorageWithOptions creates a new ObjectStorage with the given .git directory, cache and extra options
36-
func NewObjectStorageWithOptions(dir *dotgit.DotGit, cache cache.Object, ops Options) *ObjectStorage {
38+
func NewObjectStorageWithOptions(dir *dotgit.DotGit, deltaBaseCache cache.Object, ops Options) *ObjectStorage {
3739
return &ObjectStorage{
38-
options: ops,
39-
deltaBaseCache: cache,
40-
dir: dir,
40+
options: ops,
41+
deltaBaseCache: deltaBaseCache,
42+
simpleObjectCache: cache.NewObjectLRU(cache.MiByte),
43+
dir: dir,
4144
}
4245
}
4346

@@ -218,6 +221,10 @@ func (s *ObjectStorage) DeltaObject(t plumbing.ObjectType,
218221
}
219222

220223
func (s *ObjectStorage) getFromUnpacked(h plumbing.Hash) (obj plumbing.EncodedObject, err error) {
224+
if cacheObj, found := s.simpleObjectCache.Get(h); found {
225+
return cacheObj, nil
226+
}
227+
221228
f, err := s.dir.Object(h)
222229
if err != nil {
223230
if os.IsNotExist(err) {
@@ -249,6 +256,8 @@ func (s *ObjectStorage) getFromUnpacked(h plumbing.Hash) (obj plumbing.EncodedOb
249256
return nil, err
250257
}
251258

259+
s.simpleObjectCache.Put(obj);
260+
252261
_, err = io.Copy(w, r)
253262
return obj, err
254263
}

storage/filesystem/storage.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ func NewStorageWithOptions(fs billy.Filesystem, cache cache.Object, ops Options)
5151
fs: fs,
5252
dir: dir,
5353

54-
ObjectStorage: ObjectStorage{
55-
options: ops,
56-
deltaBaseCache: cache,
57-
dir: dir,
58-
},
54+
ObjectStorage: *NewObjectStorageWithOptions(dir, cache, ops),
5955
ReferenceStorage: ReferenceStorage{dir: dir},
6056
IndexStorage: IndexStorage{dir: dir},
6157
ShallowStorage: ShallowStorage{dir: dir},

0 commit comments

Comments
 (0)