Skip to content

Commit 91460a6

Browse files
author
Jiri Malek
committed
Allow in-memory cache size to be configured.
1 parent 0bf7197 commit 91460a6

4 files changed

Lines changed: 10 additions & 2 deletions

File tree

internal/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ type Database struct {
108108
// Cache represents the cache sub-system configuration.
109109
type Cache struct {
110110
Eviction time.Duration `mapstructure:"eviction"`
111+
MaxSize int `mapstructure:"size"`
111112
}
112113

113114
// Compiler represents the contract compilers configuration.

internal/config/default.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ const (
5353
// defCacheEvictionTime holds default time for in-memory eviction periods
5454
defCacheEvictionTime = 15 * time.Minute
5555

56+
// defCacheMax size represents the default max size of the cache in MB
57+
defCacheMaxSize = 4096
58+
5659
// defSolCompilerPath represents the default SOL compiler path
5760
defSolCompilerPath = "/usr/bin/solc"
5861

@@ -108,13 +111,16 @@ func applyDefaults(cfg *viper.Viper) {
108111
cfg.SetDefault(keyLachesisUrl, defLachesisUrl)
109112
cfg.SetDefault(keyMongoUrl, defMongoUrl)
110113
cfg.SetDefault(keyMongoDatabase, defMongoDatabase)
111-
cfg.SetDefault(keyCacheEvictionTime, defCacheEvictionTime)
112114
cfg.SetDefault(keySolCompilerPath, defSolCompilerPath)
113115
cfg.SetDefault(keyApiPeers, defApiPeers)
114116
cfg.SetDefault(keyApiStateOrigin, defApiStateOrigin)
115117
cfg.SetDefault(keyErc20TokenMapFilePath, defTokenLogoFilePath)
116118
cfg.SetDefault(keyErc20Logos, defERC20Logo)
117119

120+
// in-memory cache
121+
cfg.SetDefault(keyCacheEvictionTime, defCacheEvictionTime)
122+
cfg.SetDefault(keyCacheMaxSize, defCacheMaxSize)
123+
118124
// server timeouts
119125
cfg.SetDefault(keyTimeoutRead, defReadTimeout)
120126
cfg.SetDefault(keyTimeoutWrite, defWriteTimeout)

internal/config/keys.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const (
4444

4545
// cache related options
4646
keyCacheEvictionTime = "cache.eviction"
47+
keyCacheMaxSize = "cache.size"
4748

4849
// contract validation related
4950
keySolCompilerPath = "compiler.sol"

internal/repository/cache/bridge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func cacheConfig(cfg *config.Config, log logger.Logger) bigcache.Config {
7777
// cache will not allocate more memory than this limit, value in MB
7878
// if value is reached then the oldest entries can be overridden for the new ones
7979
// 0 value means no size limit
80-
HardMaxCacheSize: 2048,
80+
HardMaxCacheSize: cfg.Cache.MaxSize,
8181

8282
// callback fired when the oldest entry is removed because of its expiration time or no space left
8383
// for the new entry, or because delete was called. A bitmask representing the reason will be returned.

0 commit comments

Comments
 (0)