Skip to content

Commit

Permalink
Add --data-availability.local-cache.max-size-mb
Browse files Browse the repository at this point in the history
Also removes MaxEntriesInWindow from BigCacheConfig since it was unused
in the production config and didn't expose a way to set it in the CLI.
Inspecting the BigCache code it appears to just control the intial size
and not the max size.
  • Loading branch information
Tristan-Wilson committed Mar 7, 2024
1 parent f9999e7 commit a5f4cdb
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions das/bigcache_storage_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,26 @@ import (

type BigCacheConfig struct {
// TODO add other config information like HardMaxCacheSize
Enable bool `koanf:"enable"`
Expiration time.Duration `koanf:"expiration"`
MaxEntriesInWindow int
Enable bool `koanf:"enable"`
Expiration time.Duration `koanf:"expiration"`
MaxSizeMB int `koanf:"max-size-mb"`
}

var DefaultBigCacheConfig = BigCacheConfig{
Expiration: time.Hour,
MaxSizeMB: 1024,
}

var TestBigCacheConfig = BigCacheConfig{
Enable: true,
Expiration: time.Hour,
MaxEntriesInWindow: 1000,
Enable: true,
Expiration: time.Hour,
MaxSizeMB: 128,
}

func BigCacheConfigAddOptions(prefix string, f *flag.FlagSet) {
f.Bool(prefix+".enable", DefaultBigCacheConfig.Enable, "Enable local in-memory caching of sequencer batch data")
f.Duration(prefix+".expiration", DefaultBigCacheConfig.Expiration, "Expiration time for in-memory cached sequencer batches")
f.Int(prefix+".max-size-mb", DefaultBigCacheConfig.MaxSizeMB, "Maximum size of the cache, in MB")
}

type BigCacheStorageService struct {
Expand All @@ -48,9 +50,7 @@ type BigCacheStorageService struct {

func NewBigCacheStorageService(bigCacheConfig BigCacheConfig, baseStorageService StorageService) (StorageService, error) {
conf := bigcache.DefaultConfig(bigCacheConfig.Expiration)
if bigCacheConfig.MaxEntriesInWindow > 0 {
conf.MaxEntriesInWindow = bigCacheConfig.MaxEntriesInWindow
}
conf.HardMaxCacheSize = bigCacheConfig.MaxSizeMB
bigCache, err := bigcache.NewBigCache(conf)
if err != nil {
return nil, err
Expand Down

0 comments on commit a5f4cdb

Please sign in to comment.