feat: optimize caching strategy and implement concurrency limits
This commit is contained in:
@@ -84,12 +84,15 @@ type ConfigEvent struct {
|
||||
}
|
||||
|
||||
type ConfigCache struct {
|
||||
Meta string `yaml:"meta"` // 元数据缓存
|
||||
MetaTTL time.Duration `yaml:"meta_ttl"` // 缓存时间
|
||||
Meta string `yaml:"meta"` // 元数据缓存
|
||||
MetaTTL time.Duration `yaml:"meta_ttl"` // 缓存时间
|
||||
MetaRefresh time.Duration `yaml:"meta_refresh"` // 刷新时间
|
||||
|
||||
Blob string `yaml:"blob"` // 缓存归档位置
|
||||
BlobTTL time.Duration `yaml:"blob_ttl"` // 缓存归档位置
|
||||
BlobLimit units.Base2Bytes `yaml:"blob_limit"` // 单个文件最大大小
|
||||
Blob string `yaml:"blob"` // 缓存归档位置
|
||||
BlobTTL time.Duration `yaml:"blob_ttl"` // 缓存归档位置
|
||||
BlobLimit units.Base2Bytes `yaml:"blob_limit"` // 单个文件最大大小
|
||||
BlobConcurrent uint64 `yaml:"blob_concurrent"` // 并发缓存限制
|
||||
BackendConcurrent uint64 `yaml:"backend_concurrent"` // 并发后端请求限制
|
||||
}
|
||||
|
||||
func LoadConfig(path string) (*Config, error) {
|
||||
|
||||
@@ -52,7 +52,10 @@ func main() {
|
||||
}
|
||||
defer cacheBlob.Close()
|
||||
backend := providers.NewProviderCache(gitea,
|
||||
cacheBlob.Child("backend"), uint64(config.Cache.BlobLimit),
|
||||
cacheBlob.Child("backend"),
|
||||
uint64(config.Cache.BlobLimit),
|
||||
config.Cache.BlobConcurrent,
|
||||
config.Cache.BackendConcurrent,
|
||||
)
|
||||
defer backend.Close()
|
||||
db, err := kv.NewKVFromURL(config.Database.URL)
|
||||
@@ -74,7 +77,7 @@ func main() {
|
||||
db,
|
||||
pkg.WithClient(http.DefaultClient),
|
||||
pkg.WithEvent(event),
|
||||
pkg.WithMetaCache(cacheMeta, config.Cache.MetaTTL),
|
||||
pkg.WithMetaCache(cacheMeta, config.Cache.MetaTTL, config.Cache.MetaRefresh),
|
||||
pkg.WithBlobCache(cacheBlob.Child("filter"), config.Cache.BlobTTL),
|
||||
pkg.WithErrorHandler(config.ErrorHandler),
|
||||
pkg.WithFilterConfig(config.Filters),
|
||||
|
||||
Reference in New Issue
Block a user