| package performance_setting
|
|
|
| import (
|
| "github.com/QuantumNous/new-api/common"
|
| "github.com/QuantumNous/new-api/setting/config"
|
| )
|
|
|
|
|
| type PerformanceSetting struct {
|
|
|
| DiskCacheEnabled bool `json:"disk_cache_enabled"`
|
|
|
| DiskCacheThresholdMB int `json:"disk_cache_threshold_mb"`
|
|
|
| DiskCacheMaxSizeMB int `json:"disk_cache_max_size_mb"`
|
|
|
| DiskCachePath string `json:"disk_cache_path"`
|
| }
|
|
|
|
|
| var performanceSetting = PerformanceSetting{
|
| DiskCacheEnabled: false,
|
| DiskCacheThresholdMB: 10,
|
| DiskCacheMaxSizeMB: 1024,
|
| DiskCachePath: "",
|
| }
|
|
|
| func init() {
|
|
|
| config.GlobalConfig.Register("performance_setting", &performanceSetting)
|
|
|
| syncToCommon()
|
| }
|
|
|
|
|
| func syncToCommon() {
|
| common.SetDiskCacheConfig(common.DiskCacheConfig{
|
| Enabled: performanceSetting.DiskCacheEnabled,
|
| ThresholdMB: performanceSetting.DiskCacheThresholdMB,
|
| MaxSizeMB: performanceSetting.DiskCacheMaxSizeMB,
|
| Path: performanceSetting.DiskCachePath,
|
| })
|
| }
|
|
|
|
|
| func GetPerformanceSetting() *PerformanceSetting {
|
| return &performanceSetting
|
| }
|
|
|
|
|
|
|
| func UpdateAndSync() {
|
| syncToCommon()
|
| }
|
|
|
|
|
| func GetCacheStats() common.DiskCacheStats {
|
| return common.GetDiskCacheStats()
|
| }
|
|
|
|
|
| func ResetStats() {
|
| common.ResetDiskCacheStats()
|
| }
|
|
|