aboutsummaryrefslogtreecommitdiff
path: root/object/store/packed/basecache.go
diff options
context:
space:
mode:
Diffstat (limited to 'object/store/packed/basecache.go')
-rw-r--r--object/store/packed/basecache.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/object/store/packed/basecache.go b/object/store/packed/basecache.go
new file mode 100644
index 00000000..88597404
--- /dev/null
+++ b/object/store/packed/basecache.go
@@ -0,0 +1,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
+}