Skip to content

Commit

Permalink
Merge pull request #76 from gadget-inc/configure_cache_size
Browse files Browse the repository at this point in the history
Configure cache size
  • Loading branch information
angelini authored Jan 18, 2024
2 parents e1c0b40 + 11d3340 commit 5c0b3ce
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/db/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"context"
"fmt"
"io"
"os"
"strconv"

"github.com/dgraph-io/ristretto"
"github.com/jackc/pgx/v5"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5c0b3ce

Please sign in to comment.