From 18156b8847eea535899247a573c1c4311ba9ae0a Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Tue, 25 Mar 2025 03:08:10 +0800 Subject: [PATCH] Separate cache into separate files --- cache.go | 74 ----------------------------------------------------- cache_commit_path_file_html.go | 25 +++++++++++++++++++++++++ cache_commit_path_file_raw.go | 23 +++++++++++++++++++++++ cache_commit_tree_readme.go | 31 +++++++++++++++++++++++++++++++ cache_index_commits_display.go | 23 +++++++++++++++++++++++ diff --git a/cache.go b/cache.go deleted file mode 100644 index 59c400455b0d1f659cf90a9ac9eb1486494033f3..0000000000000000000000000000000000000000 --- a/cache.go +++ /dev/null @@ -1,74 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only -// SPDX-FileContributor: Runxi Yu - -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 -} - -// key = commit hash + path -var treeReadmeCache *ristretto.Cache[[]byte, treeReadmeCacheEntry] - -func init() { - var err error - treeReadmeCache, err = ristretto.NewCache(&ristretto.Config[[]byte, treeReadmeCacheEntry]{ - NumCounters: 1e4, - MaxCost: 1 << 60, - BufferItems: 8192, - }) - if err != nil { - clog.Fatal(1, "Error initializing indexPageCache: "+err.Error()) - } -} - -var indexCommitsDisplayCache *ristretto.Cache[[]byte, []commitDisplay] - -func init() { - var err error - indexCommitsDisplayCache, err = ristretto.NewCache(&ristretto.Config[[]byte, []commitDisplay]{ - NumCounters: 1e4, - MaxCost: 1 << 60, - BufferItems: 8192, - }) - if err != nil { - clog.Fatal(1, "Error initializing indexCommitsCache: "+err.Error()) - } -} - -var commitPathFileHTMLCache *ristretto.Cache[[]byte, template.HTML] - -func init() { - var err error - commitPathFileHTMLCache, err = ristretto.NewCache(&ristretto.Config[[]byte, template.HTML]{ - NumCounters: 1e4, - MaxCost: 1 << 60, - BufferItems: 8192, - }) - if err != nil { - clog.Fatal(1, "Error initializing commitPathFileHTMLCache: "+err.Error()) - } -} - -var commitPathFileRawCache *ristretto.Cache[[]byte, string] - -func init() { - var err error - commitPathFileRawCache, err = ristretto.NewCache(&ristretto.Config[[]byte, string]{ - NumCounters: 1e4, - MaxCost: 1 << 60, - BufferItems: 8192, - }) - if err != nil { - clog.Fatal(1, "Error initializing commitPathFileRawCache: "+err.Error()) - } -} diff --git a/cache_commit_path_file_html.go b/cache_commit_path_file_html.go new file mode 100644 index 0000000000000000000000000000000000000000..ec5f67a6c5a825528ef496e872c092734788ead0 --- /dev/null +++ b/cache_commit_path_file_html.go @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// SPDX-FileContributor: Runxi Yu + +package main + +import ( + "html/template" + + "github.com/dgraph-io/ristretto/v2" + "go.lindenii.runxiyu.org/lindenii-common/clog" +) + +var commitPathFileHTMLCache *ristretto.Cache[[]byte, template.HTML] + +func init() { + var err error + commitPathFileHTMLCache, err = ristretto.NewCache(&ristretto.Config[[]byte, template.HTML]{ + NumCounters: 1e4, + MaxCost: 1 << 60, + BufferItems: 8192, + }) + if err != nil { + clog.Fatal(1, "Error initializing commitPathFileHTMLCache: "+err.Error()) + } +} diff --git a/cache_commit_path_file_raw.go b/cache_commit_path_file_raw.go new file mode 100644 index 0000000000000000000000000000000000000000..4a4de6206322d4148d442f019b258258b2a8dc0a --- /dev/null +++ b/cache_commit_path_file_raw.go @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// SPDX-FileContributor: Runxi Yu + +package main + +import ( + "github.com/dgraph-io/ristretto/v2" + "go.lindenii.runxiyu.org/lindenii-common/clog" +) + +var commitPathFileRawCache *ristretto.Cache[[]byte, string] + +func init() { + var err error + commitPathFileRawCache, err = ristretto.NewCache(&ristretto.Config[[]byte, string]{ + NumCounters: 1e4, + MaxCost: 1 << 60, + BufferItems: 8192, + }) + if err != nil { + clog.Fatal(1, "Error initializing commitPathFileRawCache: "+err.Error()) + } +} diff --git a/cache_commit_tree_readme.go b/cache_commit_tree_readme.go new file mode 100644 index 0000000000000000000000000000000000000000..dcd5f9c59098944115b27e0b421e82074ac6bc3e --- /dev/null +++ b/cache_commit_tree_readme.go @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// SPDX-FileContributor: Runxi Yu + +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 << 60, + BufferItems: 8192, + }) + if err != nil { + clog.Fatal(1, "Error initializing indexPageCache: "+err.Error()) + } +} diff --git a/cache_index_commits_display.go b/cache_index_commits_display.go new file mode 100644 index 0000000000000000000000000000000000000000..5d809437c95d9c17ab16b29f8635d1c86093c6e2 --- /dev/null +++ b/cache_index_commits_display.go @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// SPDX-FileContributor: Runxi Yu + +package main + +import ( + "github.com/dgraph-io/ristretto/v2" + "go.lindenii.runxiyu.org/lindenii-common/clog" +) + +var indexCommitsDisplayCache *ristretto.Cache[[]byte, []commitDisplay] + +func init() { + var err error + indexCommitsDisplayCache, err = ristretto.NewCache(&ristretto.Config[[]byte, []commitDisplay]{ + NumCounters: 1e4, + MaxCost: 1 << 60, + BufferItems: 8192, + }) + if err != nil { + clog.Fatal(1, "Error initializing indexCommitsCache: "+err.Error()) + } +} -- 2.48.1