@@ -23,21 +23,24 @@ type ObjectStorage struct {
23
23
// deltaBaseCache is an object cache uses to cache delta's bases when
24
24
deltaBaseCache cache.Object
25
25
26
+ simpleObjectCache cache.Object
27
+
26
28
dir * dotgit.DotGit
27
29
index map [plumbing.Hash ]idxfile.Index
28
30
}
29
31
30
32
// 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 {})
33
35
}
34
36
35
37
// 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 {
37
39
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 ,
41
44
}
42
45
}
43
46
@@ -218,6 +221,10 @@ func (s *ObjectStorage) DeltaObject(t plumbing.ObjectType,
218
221
}
219
222
220
223
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
+
221
228
f , err := s .dir .Object (h )
222
229
if err != nil {
223
230
if os .IsNotExist (err ) {
@@ -249,6 +256,8 @@ func (s *ObjectStorage) getFromUnpacked(h plumbing.Hash) (obj plumbing.EncodedOb
249
256
return nil , err
250
257
}
251
258
259
+ s .simpleObjectCache .Put (obj );
260
+
252
261
_ , err = io .Copy (w , r )
253
262
return obj , err
254
263
}
0 commit comments