provider: add store_providers cache_file option to gate subscription caching

This commit is contained in:
Shtorm
2026-09-04 05:19:05 +03:00
parent de3c7ff37e
commit 102330f968
5 changed files with 17 additions and 3 deletions
+1
View File
@@ -43,6 +43,7 @@ type CacheFile interface {
StoreWARPConfig() bool
StoreMASQUEConfig() bool
StoreProviders() bool
StoreDNS() bool
DNSCacheStore
+6
View File
@@ -94,5 +94,11 @@
"final": "auto",
"default_domain_resolver": "default",
"auto_detect_interface": true
},
"experimental": {
"cache_file": {
"enabled": true,
"store_providers": true // For persisting fetched subscriptions across restarts
}
}
}
+6
View File
@@ -51,6 +51,7 @@ type CacheFile struct {
storeDNS bool
storeWARPConfig bool
storeMASQUEConfig bool
storeProviders bool
disableExpire bool
rdrcTimeout time.Duration
optimisticTimeout time.Duration
@@ -115,6 +116,7 @@ func New(ctx context.Context, logger logger.Logger, options option.CacheFileOpti
storeDNS: options.StoreDNS,
storeWARPConfig: options.StoreWARPConfig,
storeMASQUEConfig: options.StoreMASQUEConfig,
storeProviders: options.StoreProviders,
rdrcTimeout: rdrcTimeout,
saveDomain: make(map[netip.Addr]string),
saveAddress4: make(map[string]netip.Addr),
@@ -485,6 +487,10 @@ func (c *CacheFile) StoreMASQUEConfig() bool {
return c.storeMASQUEConfig
}
func (c *CacheFile) StoreProviders() bool {
return c.storeProviders
}
func (c *CacheFile) LoadWARPConfig(tag string) *adapter.SavedBinary {
var savedConfig adapter.SavedBinary
err := c.DB.View(func(t *bbolt.Tx) error {
+1
View File
@@ -18,6 +18,7 @@ type CacheFileOptions struct {
StoreRDRC bool `json:"store_rdrc,omitempty" schema:"omit"`
StoreWARPConfig bool `json:"store_warp_config,omitempty"`
StoreMASQUEConfig bool `json:"store_masque_config,omitempty"`
StoreProviders bool `json:"store_providers,omitempty"`
RDRCTimeout badoption.Duration `json:"rdrc_timeout,omitempty"`
StoreDNS bool `json:"store_dns,omitempty"`
}
+3 -3
View File
@@ -106,7 +106,7 @@ func NewProviderRemote(ctx context.Context, router adapter.Router, logFactory lo
func (s *ProviderRemote) Start() error {
s.cacheFile = service.FromContext[adapter.CacheFile](s.ctx)
if s.cacheFile != nil {
if s.cacheFile != nil && s.cacheFile.StoreProviders() {
if saveSub := s.cacheFile.LoadSubscription(s.Tag()); saveSub != nil {
content, _ := boxCommon.DecodeBase64URLSafe(string(saveSub.Content))
firstLine, others := getFirstLine(content)
@@ -207,7 +207,7 @@ func (s *ProviderRemote) fetch(ctx context.Context) error {
case http.StatusNotModified:
s.subscriptionInfo = info
s.lastUpdated = time.Now()
if s.cacheFile != nil {
if s.cacheFile != nil && s.cacheFile.StoreProviders() {
saveSub := s.cacheFile.LoadSubscription(s.Tag())
if saveSub != nil {
if hasInfo {
@@ -251,7 +251,7 @@ func (s *ProviderRemote) fetch(ctx context.Context) error {
s.UpdateGroups()
s.subscriptionInfo = info
s.lastUpdated = time.Now()
if s.cacheFile != nil {
if s.cacheFile != nil && s.cacheFile.StoreProviders() {
content, _ := json.Marshal(option.Options{
Outbounds: s.lastOutOpts,
})