mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-11 17:56:37 +08:00
perf(config): add Otter RAM cache layer for system configs
Introduce pkg/cache/ram on top of existing Redis/DB config reads. GetByKey now checks local RAM before Redis. Unified invalidation clears RAM and Redis hash fields on admin writes, with pub/sub for multi-node RAM eviction. Add tests and wire create/update/migrator write paths.
This commit is contained in:
@@ -87,16 +87,16 @@ func CreateSystemConfig(c *gin.Context) {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := db.HSetJSON(c.Request.Context(), model.SystemConfigRedisHashKey, req.Key, &config); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, response.Err(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if err := model.InvalidateSystemConfigCache(c.Request.Context(), req.Key); err != nil {
|
||||
logger.WarnF(c.Request.Context(), "清理系统配置缓存失败: %v", err)
|
||||
}
|
||||
|
||||
if err := model.InvalidateVisibleSystemConfigsCache(c.Request.Context()); err != nil {
|
||||
logger.WarnF(c.Request.Context(), "清理公共配置列表缓存失败: %v", err)
|
||||
}
|
||||
@@ -233,10 +233,6 @@ func UpdateSystemConfig(c *gin.Context) {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := db.HSetJSON(c.Request.Context(), model.SystemConfigRedisHashKey, key, &config); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resolveStorageMigrationTasksOnDirectDriverUpdate(
|
||||
c.Request.Context(),
|
||||
tx,
|
||||
@@ -287,6 +283,10 @@ func resolveStorageMigrationTasksOnDirectDriverUpdate(
|
||||
}
|
||||
|
||||
func invalidateCachesAfterConfigUpdate(ctx context.Context, key string) {
|
||||
if err := model.InvalidateSystemConfigCache(ctx, key); err != nil {
|
||||
logger.WarnF(ctx, "清理系统配置缓存失败: %v", err)
|
||||
}
|
||||
|
||||
if key == model.ConfigKeyStorageConfig {
|
||||
upload.ResetAccessCaches()
|
||||
upload.PublishAccessCacheInvalidation(ctx)
|
||||
|
||||
Reference in New Issue
Block a user