f
This commit is contained in:
@@ -20,60 +20,60 @@ func SetupGormCache(db *gorm.DB, cacheService interfaces.CacheService, cfg *conf
|
||||
|
||||
// 以下是原有的缓存配置代码,已注释掉
|
||||
/*
|
||||
// 创建缓存配置
|
||||
cacheConfig := cache.CacheConfig{
|
||||
DefaultTTL: 30 * time.Minute,
|
||||
TablePrefix: "gorm_cache",
|
||||
MaxCacheSize: 1000,
|
||||
CacheComplexSQL: false,
|
||||
EnableStats: true,
|
||||
EnableWarmup: true,
|
||||
PenetrationGuard: true,
|
||||
BloomFilter: false,
|
||||
AutoInvalidate: true,
|
||||
InvalidateDelay: 100 * time.Millisecond,
|
||||
// 创建缓存配置
|
||||
cacheConfig := cache.CacheConfig{
|
||||
DefaultTTL: 30 * time.Minute,
|
||||
TablePrefix: "gorm_cache",
|
||||
MaxCacheSize: 1000,
|
||||
CacheComplexSQL: false,
|
||||
EnableStats: true,
|
||||
EnableWarmup: true,
|
||||
PenetrationGuard: true,
|
||||
BloomFilter: false,
|
||||
AutoInvalidate: true,
|
||||
InvalidateDelay: 100 * time.Millisecond,
|
||||
|
||||
// 配置启用缓存的表
|
||||
EnabledTables: []string{
|
||||
// "product",
|
||||
// "product_category",
|
||||
// "enterprise_info_submit_records",
|
||||
// "sms_codes",
|
||||
// "wallets",
|
||||
// "subscription",
|
||||
// "product_category",
|
||||
// "product_documentation",
|
||||
// "enterprise_infos",
|
||||
// "api_users",
|
||||
// 添加更多需要缓存的表
|
||||
},
|
||||
// 配置启用缓存的表
|
||||
EnabledTables: []string{
|
||||
// "product",
|
||||
// "product_category",
|
||||
// "enterprise_info_submit_records",
|
||||
// "sms_codes",
|
||||
// "wallets",
|
||||
// "subscription",
|
||||
// "product_category",
|
||||
// "product_documentation",
|
||||
// "enterprise_infos",
|
||||
// "api_users",
|
||||
// 添加更多需要缓存的表
|
||||
},
|
||||
|
||||
// 配置禁用缓存的表(日志表等)
|
||||
DisabledTables: []string{
|
||||
"audit_logs", // 审计日志
|
||||
"system_logs", // 系统日志
|
||||
"operation_logs", // 操作日志
|
||||
"api_calls", // API调用日志表,变化频繁,不适合缓存
|
||||
},
|
||||
}
|
||||
// 配置禁用缓存的表(日志表等)
|
||||
DisabledTables: []string{
|
||||
"audit_logs", // 审计日志
|
||||
"system_logs", // 系统日志
|
||||
"operation_logs", // 操作日志
|
||||
"api_calls", // API调用日志表,变化频繁,不适合缓存
|
||||
},
|
||||
}
|
||||
|
||||
// 初始化全局缓存配置管理器
|
||||
cache.InitCacheConfigManager(cacheConfig)
|
||||
// 初始化全局缓存配置管理器
|
||||
cache.InitCacheConfigManager(cacheConfig)
|
||||
|
||||
// 创建缓存插件
|
||||
cachePlugin := cache.NewGormCachePlugin(cacheService, logger, cacheConfig)
|
||||
// 创建缓存插件
|
||||
cachePlugin := cache.NewGormCachePlugin(cacheService, logger, cacheConfig)
|
||||
|
||||
// 注册插件到GORM
|
||||
if err := db.Use(cachePlugin); err != nil {
|
||||
logger.Error("注册GORM缓存插件失败", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
// 注册插件到GORM
|
||||
if err := db.Use(cachePlugin); err != nil {
|
||||
logger.Error("注册GORM缓存插件失败", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Info("GORM缓存插件已成功注册",
|
||||
zap.Duration("default_ttl", cacheConfig.DefaultTTL),
|
||||
zap.Strings("enabled_tables", cacheConfig.EnabledTables),
|
||||
zap.Strings("disabled_tables", cacheConfig.DisabledTables),
|
||||
)
|
||||
logger.Info("GORM缓存插件已成功注册",
|
||||
zap.Duration("default_ttl", cacheConfig.DefaultTTL),
|
||||
zap.Strings("enabled_tables", cacheConfig.EnabledTables),
|
||||
zap.Strings("disabled_tables", cacheConfig.DisabledTables),
|
||||
)
|
||||
*/
|
||||
|
||||
// return nil
|
||||
@@ -103,13 +103,13 @@ func GetCacheConfig(cfg *config.Config) cache.CacheConfig {
|
||||
},
|
||||
|
||||
DisabledTables: []string{
|
||||
"api_calls", // API调用日志表,变化频繁,不适合缓存
|
||||
"api_calls", // API调用日志表,变化频繁,不适合缓存
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
// 初始化全局缓存配置管理器
|
||||
cache.InitCacheConfigManager(cacheConfig)
|
||||
|
||||
|
||||
return cacheConfig
|
||||
}
|
||||
|
||||
@@ -134,13 +134,13 @@ func GetCacheConfig(cfg *config.Config) cache.CacheConfig {
|
||||
},
|
||||
|
||||
DisabledTables: []string{
|
||||
"api_calls", // API调用日志表,变化频繁,不适合缓存
|
||||
"api_calls", // API调用日志表,变化频繁,不适合缓存
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
// 初始化全局缓存配置管理器
|
||||
cache.InitCacheConfigManager(cacheConfig)
|
||||
|
||||
|
||||
return cacheConfig
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user