summaryrefslogtreecommitdiff
path: root/main.go
diff options
from:
to:
context:
space:
mode:
authorGravatar SayaAndy <saya.andy@posteo.com> 2025-08-31 18:40:13 +0700
committerGravatar SayaAndy <saya.andy@posteo.com> 2025-08-31 18:40:13 +0700
commit6af14241ff2c8050753f1d6ac702a938a017a839 (patch)
tree29400fa749d7bc87ed30cc924e486791f8f72867 /main.go
parentf174579ef53fb726594a2f7064299b86c8691ea3 (diff)
downloadweb-6af14241ff2c8050753f1d6ac702a938a017a839.tar.gz
web-6af14241ff2c8050753f1d6ac702a938a017a839.zip
feat: add page cache
Diffstat (limited to 'main.go')
-rw-r--r--main.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/main.go b/main.go
index 72eca3d..e4e5a45 100644
--- a/main.go
+++ b/main.go
@@ -15,6 +15,7 @@ import (
"github.com/SayaAndy/saya-today-web/internal/router"
"github.com/SayaAndy/saya-today-web/internal/tailwind"
"github.com/SayaAndy/saya-today-web/locale"
+ "github.com/dgraph-io/ristretto/v2"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/redirect"
"github.com/golang-migrate/migrate/v4"
@@ -116,7 +117,17 @@ func main() {
router.CCache, err = router.NewClientCache(db, []byte(cfg.Auth.Salt))
if err != nil {
- slog.Error("fail to initialize cache", slog.String("error", err.Error()))
+ slog.Error("fail to initialize client cache", slog.String("error", err.Error()))
+ os.Exit(1)
+ }
+
+ router.PCache, err = ristretto.NewCache(&ristretto.Config[string, []byte]{
+ NumCounters: 1e6, // 1,000,000
+ MaxCost: 1 << 29, // 512 MB
+ BufferItems: 64, // number of keys per Get buffer.
+ })
+ if err != nil {
+ slog.Error("fail to initialize page cache", slog.String("error", err.Error()))
os.Exit(1)
}
@@ -158,5 +169,6 @@ func main() {
if err = db.Close(); err != nil {
slog.Error("fail to close db connection", slog.String("error", err.Error()))
}
+ router.PCache.Close()
db.Close()
}