Files
urldb/config/sync.go

31 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package config
import (
"github.com/ctwj/urldb/db/repo"
"github.com/ctwj/urldb/utils"
)
// SyncWithRepository 同步配置管理器与Repository的缓存
func (cm *ConfigManager) SyncWithRepository(repoManager *repo.RepositoryManager) {
// 监听配置变更事件并同步缓存
// 这是一个抽象概念实际实现需要修改Repository接口
// 当配置更新时通知Repository清理缓存
go func() {
watcher := cm.AddConfigWatcher()
for {
select {
case key := <-watcher:
// 通知Repository层清理缓存如果Repository支持
utils.Debug("配置 %s 已更新可能需要同步到Repository缓存", key)
}
}
}()
}
// UpdateRepositoryCache 当配置管理器更新配置时通知Repository层同步
func (cm *ConfigManager) UpdateRepositoryCache(repoManager *repo.RepositoryManager) {
// 这个函数需要Repository支持特定的缓存清理方法
// 由于现有Repository没有提供这样的接口我们只能依赖数据库同步
utils.Info("配置已通过配置管理器更新Repository层将从数据库重新加载")
}