2022-08-16 23:30:23 +08:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
2023-01-09 22:55:10 +08:00
|
|
|
"time"
|
|
|
|
|
2022-10-17 16:32:31 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/global"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/init/cache/badger_db"
|
2023-05-09 15:23:43 +08:00
|
|
|
"github.com/dgraph-io/badger/v4"
|
2022-08-16 23:30:23 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func Init() {
|
2023-01-09 22:55:10 +08:00
|
|
|
c := global.CONF.System.Cache
|
2022-08-16 23:30:23 +08:00
|
|
|
|
2022-08-25 17:54:52 +08:00
|
|
|
options := badger.Options{
|
2023-01-09 22:55:10 +08:00
|
|
|
Dir: c,
|
|
|
|
ValueDir: c,
|
2022-08-25 17:54:52 +08:00
|
|
|
ValueLogFileSize: 102400000,
|
|
|
|
ValueLogMaxEntries: 100000,
|
|
|
|
VLogPercentile: 0.1,
|
|
|
|
|
|
|
|
MemTableSize: 64 << 20,
|
|
|
|
BaseTableSize: 2 << 20,
|
|
|
|
BaseLevelSize: 10 << 20,
|
|
|
|
TableSizeMultiplier: 2,
|
|
|
|
LevelSizeMultiplier: 10,
|
|
|
|
MaxLevels: 7,
|
|
|
|
NumGoroutines: 8,
|
|
|
|
MetricsEnabled: true,
|
|
|
|
NumCompactors: 4,
|
|
|
|
NumLevelZeroTables: 5,
|
|
|
|
NumLevelZeroTablesStall: 15,
|
|
|
|
NumMemtables: 5,
|
|
|
|
BloomFalsePositive: 0.01,
|
|
|
|
BlockSize: 4 * 1024,
|
|
|
|
SyncWrites: false,
|
|
|
|
NumVersionsToKeep: 1,
|
|
|
|
CompactL0OnClose: false,
|
|
|
|
VerifyValueChecksum: false,
|
|
|
|
BlockCacheSize: 256 << 20,
|
|
|
|
IndexCacheSize: 0,
|
|
|
|
ZSTDCompressionLevel: 1,
|
|
|
|
EncryptionKey: []byte{},
|
|
|
|
EncryptionKeyRotationDuration: 10 * 24 * time.Hour, // Default 10 days.
|
|
|
|
DetectConflicts: true,
|
|
|
|
NamespaceOffset: -1,
|
|
|
|
}
|
|
|
|
|
|
|
|
cache, err := badger.Open(options)
|
2022-08-16 23:30:23 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
global.CACHE = badger_db.NewCacheDB(cache)
|
2023-03-01 18:17:31 +08:00
|
|
|
global.LOG.Info("init cache successfully")
|
2022-08-16 23:30:23 +08:00
|
|
|
}
|