From 11d33404f29757cce957bce025839a9201471b53 Mon Sep 17 00:00:00 2001 From: Alex Angelini Date: Thu, 18 Jan 2024 09:54:14 -0500 Subject: [PATCH] Configure cache size --- internal/db/content.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/db/content.go b/internal/db/content.go index c73ad50..520bc2d 100644 --- a/internal/db/content.go +++ b/internal/db/content.go @@ -5,6 +5,8 @@ import ( "context" "fmt" "io" + "os" + "strconv" "github.com/dgraph-io/ristretto" "github.com/jackc/pgx/v5" @@ -141,9 +143,18 @@ type ContentLookup struct { } func NewContentLookup() (*ContentLookup, error) { + cacheSize := int64(1_000) + cacheSizeEnv := os.Getenv("DL_CACHE_SIZE") + if cacheSizeEnv != "" { + size, err := strconv.ParseInt(cacheSizeEnv, 10, 64) + if err == nil { + cacheSize = size + } + } + cache, err := ristretto.NewCache(&ristretto.Config{ NumCounters: 100_000, - MaxCost: 1_000 * MB, + MaxCost: cacheSize * MB, BufferItems: 64, }) if err != nil {