refactor(cache)!: extract hybrid_cache package (#2477)

* refactor(HybridCache)!: extract hybrid_cache package and rename cache_threshold to auto_memory_limit

* split HybridCache and stores into internal/hybrid_cache package
* introduce BackingStore abstraction with BufferStore and FileStore
* rename CacheThreshold to AutoMemoryLimit in config/env/bootstrap
* update stream/request integration and related tests

* rename singleFileCache and MultiFileCache to singleFileStore and MultiFileStore

* refactor(HybridCache): improve memory management strategies in NewHybridCache

* rename

* alias hybrid_cache to hcache

* omments
This commit is contained in:
j2rong4cn
2026-05-18 15:11:39 +08:00
committed by GitHub
parent daad21ef91
commit 9eae62581a
19 changed files with 476 additions and 603 deletions
+2 -2
View File
@@ -120,9 +120,9 @@ type Config struct {
DistDir string `json:"dist_dir"`
Log LogConfig `json:"log" envPrefix:"LOG_"`
DelayedStart int `json:"delayed_start" env:"DELAYED_START"`
AutoMemoryLimit int `json:"auto_memory_limit" env:"AUTO_MEMORY_LIMIT"`
MinFreeMemory int `json:"min_free_memory" env:"MIN_FREE_MEMORY"`
MaxBlockLimit int `json:"max_block_limit" env:"MAX_BLOCK_LIMIT"`
CacheThreshold int `json:"cache_threshold" env:"CACHE_THRESHOLD"`
MaxConnections int `json:"max_connections" env:"MAX_CONNECTIONS"`
MaxConcurrency int `json:"max_concurrency" env:"MAX_CONCURRENCY"`
TlsInsecureSkipVerify bool `json:"tls_insecure_skip_verify" env:"TLS_INSECURE_SKIP_VERIFY"`
@@ -179,7 +179,7 @@ func DefaultConfig(dataDir string) *Config {
},
},
},
CacheThreshold: 4,
AutoMemoryLimit: 4,
MaxConnections: 0,
MaxConcurrency: 64,
TlsInsecureSkipVerify: false,
+6 -6
View File
@@ -25,16 +25,16 @@ var FilenameCharMap = make(map[string]string)
var PrivacyReg []*regexp.Regexp
var (
// 限制单次内存的扩容大小,超过该阈值将分多次扩容。
// CacheThreshold大于0时,也限制 Downloader 的PartSize
MaxBlockLimit uint64 = 16 * 1024 * 1024
// 大于该阈值的数据流将使用HybridCache,可主动释放内存。
// 否则使用Go的内存分配,直到GC回收。
CacheThreshold uint64 = 4 * 1024 * 1024
// 在HybridCache中使用[]byte缓存数据流的限制,内存为Go自动管理,直到GC
AutoMemoryLimit uint64 = 4 * 1024 * 1024
// 最小空闲内存,当内存不足时,HybridCache会回退到文件缓存。
// 如果为0,HybridCache会使用文件缓存,不占用内存。
MinFreeMemory uint64 = 16 * 1024 * 1024
// 限制HybridCache手动管理内存单次的扩容大小,超过该阈值将分多次扩容。
// MinFreeMemory大于0时,也限制 Downloader 的PartSize
MaxBlockLimit uint64 = 16 * 1024 * 1024
)
var (
RawIndexHtml string
ManageHtml string