aboutsummaryrefslogtreecommitdiff
path: root/cache.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-22 22:04:25 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-22 22:04:25 +0800
commitcf735091ac163cbaafda8a12ead568bf4ed8abbf (patch)
treefda3c9f96040991730d090a3a05809decc2588b1 /cache.go
parentCache tree-building (diff)
downloadforge-cf735091ac163cbaafda8a12ead568bf4ed8abbf.tar.gz
forge-cf735091ac163cbaafda8a12ead568bf4ed8abbf.tar.zst
forge-cf735091ac163cbaafda8a12ead568bf4ed8abbf.zip
Reuse the cache for /tree
Diffstat (limited to 'cache.go')
-rw-r--r--cache.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/cache.go b/cache.go
new file mode 100644
index 0000000..e745884
--- /dev/null
+++ b/cache.go
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// SPDX-FileContributor: Runxi Yu <https://runxiyu.org>
+
+package main
+
+import (
+ "html/template"
+
+ "github.com/dgraph-io/ristretto/v2"
+ "go.lindenii.runxiyu.org/lindenii-common/clog"
+)
+
+type treeReadmeCacheEntry struct {
+ DisplayTree []displayTreeEntry
+ ReadmeFilename string
+ ReadmeRendered template.HTML
+}
+
+var treeReadmeCache *ristretto.Cache[[]byte, treeReadmeCacheEntry]
+
+func init() {
+ var err error
+ treeReadmeCache, err = ristretto.NewCache(&ristretto.Config[[]byte, treeReadmeCacheEntry]{
+ NumCounters: 1e4,
+ MaxCost: 1 << 30,
+ BufferItems: 64,
+ })
+ if err != nil {
+ clog.Fatal(1, "Error initializing indexPageCache: "+err.Error())
+ }
+}