aboutsummaryrefslogtreecommitdiff
path: root/object/store/packed/basecache.go
blob: 885974046049c72690051a51d6a891acad72e525 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package packed

import (
	"lindenii.org/go/furgit/internal/cache/clock"
	"lindenii.org/go/furgit/internal/format/packfile"
)

// baseCacheMaxWeight bounds the delta base cache weight.
const baseCacheMaxWeight = 96 << 20

// baseKey addresses an entry in one pack
// as a delta base cache key.
type baseKey struct {
	pack   *pack
	offset int
}

// cachedBase is a cached delta base, i.e.,
// its resolved object entry type and full content.
//
// content is shared with concurrent users;
// it may only be returned to callers as a copy.
//
// Labels: Mut-No.
type cachedBase struct {
	entryType packfile.EntryType
	content   []byte
}

// newBaseCache creates the delta base cache.
func newBaseCache() *clock.Clock[baseKey, cachedBase] {
	return clock.New(baseCacheMaxWeight, baseWeight)
}

// baseWeight weighs one cached delta base.
func baseWeight(_ baseKey, base cachedBase) uint64 {
	return uint64(len(base.content)) + 32
}