What is Badger

BadgerDB is an embeddable, persistent and fast key-value (KV) database written in pure Go. It is the underlying database for Dgraph, a fast, distributed graph database. It’s meant to be a performant alternative to non-Go-based key-value stores like RocksDB.

Github repository

https://github.com/dgraph-io/badger

Use Badger

With Caddy

You have to build your caddy instance including Souin and Badger using xcaddy (refer to the build caddy section).

  xcaddy build --with github.com/darkweak/souin/plugins/caddy --with github.com/darkweak/storages/badger/caddy
  

You will be able to use badger in your Caddyfile or JSON configuration file.

  {
    cache {
        ttl 1h
        badger
    }
}

route {
    cache
    respond "Hello HTTP cache"
}
  

Configuration

You can find the configuration for Badger here or check the values table below.

Values

Key nametyperequired
Dirstring
ValueDirstring
SyncWritesbool
NumVersionsToKeepint
ReadOnlybool
InMemorybool
MetricsEnabledbool
NumGoroutinesint
MemTableSizeint64
BaseTableSizeint64
BaseLevelSizeint64
LevelSizeMultiplierint
TableSizeMultiplierint
MaxLevelsint
VLogPercentilefloat64
ValueThresholdint64
NumMemtablesint
BlockSizeint
BloomFalsePositivefloat64
BlockCacheSizeint64
IndexCacheSizeint64
NumLevelZeroTablesint
NumLevelZeroTablesStallint
ValueLogFileSizeint64
ValueLogMaxEntriesuint32
NumCompactorsint
CompactL0OnClosebool
LmaxCompactionbool
ZSTDCompressionLevelint
VerifyValueChecksumbool
EncryptionKey[]byte
EncryptionKeyRotationDurationtime.Duration
BypassLockGuardbool
DetectConflictsbool
NamespaceOffsetint
ExternalMagicVersionuint16