Files
artalkjs/server/handler/cache_flush.go
qwqcode cf7725edba refactor(go): bump the module version and support go install (#979)
BREAKING CHANGE: The original Go module name was `github.com/ArtalkJS/Artalk`, which has now been modified to `github.com/artalkjs/artalk/v2` (all lowercase). This change may affect the CI pipeline or other areas if you are compiling the Artalk server and have specified the fixed Go module name. Regarding the original `-ldflags -X github.com/ArtalkJS/Artalk/internal/config.Version` and `CommitHash` definitions, please remove them, as they are now obsolete. The `Version` has been hardcoded into the Go code, and the `CommitHash` is now read from the Go build info via runtime/debug’s vcs.revision value. This change only affects the server developers and does not impact the frontend UI client.
2024-09-18 21:43:43 +08:00

35 lines
945 B
Go

package handler
import (
"github.com/artalkjs/artalk/v2/internal/core"
"github.com/artalkjs/artalk/v2/internal/i18n"
"github.com/artalkjs/artalk/v2/server/common"
"github.com/gofiber/fiber/v2"
)
// @Id FlushCache
// @Summary Flush Cache
// @Description Flush all cache on the server
// @Tags Cache
// @Security ApiKeyAuth
// @Success 200 {object} Map{msg=string}
// @Failure 403 {object} Map{msg=string}
// @Failure 400 {object} Map{msg=string}
// @Produce json
// @Router /cache/flush [post]
func CacheFlush(app *core.App, router fiber.Router) {
router.Post("/cache/flush", common.AdminGuard(app, func(c *fiber.Ctx) error {
if !app.Conf().Cache.Enabled {
return common.RespError(c, 400, "cache disabled")
}
go func() {
app.Dao().CacheFlushAll()
}()
return common.RespData(c, Map{
"msg": i18n.T("Task executing in background, please wait..."),
})
}))
}