feat(push): implement Redis caching for push events and custom channels

- Implement cached queries in GetActivePushEventByKey and GetActivePushChannelByName.
- Set TTL for cached items to 24 hours via activePushEventCacheTTL and activePushChannelCacheTTL constants.
- Implement GORM hooks (AfterSave and AfterDelete) on PushEvent and PushChannel to auto-evict Redis caches, guaranteeing cache consistency.
- Evict Redis caches manually inside API handlers for Create/Update/Delete/Toggle event/channel endpoints.
- Update events.go to query models through the new caching methods.
This commit is contained in:
ryan
2026-06-16 10:19:06 +08:00
parent 9515f0811b
commit 9fa38dcfdc
5 changed files with 108 additions and 8 deletions
+12
View File
@@ -231,6 +231,9 @@ func CreateEvent(c *gin.Context) {
return
}
// 缓存一致性:清除旧事件缓存
model.DeleteActivePushEventCache(ctx, event.EventKey)
c.JSON(http.StatusOK, response.OK(event))
}
@@ -267,6 +270,9 @@ func DeleteEvent(c *gin.Context) {
return
}
// 缓存一致性:清除事件缓存
model.DeleteActivePushEventCache(ctx, event.EventKey)
c.JSON(http.StatusOK, response.OKNil())
}
@@ -320,6 +326,9 @@ func UpdateEvent(c *gin.Context) {
return
}
// 缓存一致性:清除事件缓存
model.DeleteActivePushEventCache(c.Request.Context(), event.EventKey)
c.JSON(http.StatusOK, response.OKNil())
}
@@ -360,6 +369,9 @@ func ToggleEvent(c *gin.Context) {
return
}
// 缓存一致性:清除事件缓存
model.DeleteActivePushEventCache(c.Request.Context(), event.EventKey)
c.JSON(http.StatusOK, response.OK(event.Enabled))
}