add: 提交
This commit is contained in:
55
lib/cache/cache.go
vendored
Normal file
55
lib/cache/cache.go
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"ems.agt/lib/cache/badger_db"
|
||||
"ems.agt/lib/log"
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
)
|
||||
|
||||
var CACHE *badger_db.Cache
|
||||
|
||||
func Init() {
|
||||
options := badger.Options{
|
||||
Dir: "tmp/badger",
|
||||
ValueDir: "tmp/badger",
|
||||
ValueLogFileSize: 64 << 20,
|
||||
ValueLogMaxEntries: 10 << 20,
|
||||
VLogPercentile: 0.1,
|
||||
|
||||
MemTableSize: 32 << 20,
|
||||
BaseTableSize: 2 << 20,
|
||||
BaseLevelSize: 10 << 20,
|
||||
TableSizeMultiplier: 2,
|
||||
LevelSizeMultiplier: 10,
|
||||
MaxLevels: 7,
|
||||
NumGoroutines: 4,
|
||||
MetricsEnabled: true,
|
||||
NumCompactors: 2,
|
||||
NumLevelZeroTables: 5,
|
||||
NumLevelZeroTablesStall: 15,
|
||||
NumMemtables: 1,
|
||||
BloomFalsePositive: 0.01,
|
||||
BlockSize: 2 * 1024,
|
||||
SyncWrites: false,
|
||||
NumVersionsToKeep: 1,
|
||||
CompactL0OnClose: false,
|
||||
VerifyValueChecksum: false,
|
||||
BlockCacheSize: 32 << 20,
|
||||
IndexCacheSize: 0,
|
||||
ZSTDCompressionLevel: 1,
|
||||
EncryptionKey: []byte{},
|
||||
EncryptionKeyRotationDuration: 10 * 24 * time.Hour, // Default 10 days.
|
||||
DetectConflicts: true,
|
||||
NamespaceOffset: -1,
|
||||
}
|
||||
|
||||
cache, err := badger.Open(options)
|
||||
if err != nil {
|
||||
log.Errorf("failed to badger init cache:", err)
|
||||
}
|
||||
|
||||
CACHE = badger_db.NewCacheDB(cache)
|
||||
log.Info("init cache successfully")
|
||||
}
|
||||
Reference in New Issue
Block a user