mirror of
https://github.com/owncast/owncast.git
synced 2025-11-01 19:32:20 +08:00
chore: reverting the current implementation of http response caching
This commit is contained in:
101
router/router.go
101
router/router.go
@ -24,45 +24,10 @@ import (
|
||||
"github.com/owncast/owncast/router/middleware"
|
||||
"github.com/owncast/owncast/utils"
|
||||
"github.com/owncast/owncast/yp"
|
||||
|
||||
cache "github.com/victorspringer/http-cache"
|
||||
"github.com/victorspringer/http-cache/adapter/memory"
|
||||
)
|
||||
|
||||
// Start starts the router for the http, ws, and rtmp.
|
||||
func Start() error {
|
||||
// Setup a web response cache
|
||||
enableCache := !config.DisableResponseCaching
|
||||
|
||||
responseCache, err := memory.NewAdapter(
|
||||
memory.AdapterWithAlgorithm(memory.LRU),
|
||||
memory.AdapterWithCapacity(50),
|
||||
)
|
||||
if err != nil {
|
||||
log.Warn("unable to create web cache", err)
|
||||
}
|
||||
|
||||
superShortCacheClient, err := cache.NewClient(
|
||||
cache.ClientWithAdapter(responseCache),
|
||||
cache.ClientWithTTL(3*time.Second),
|
||||
)
|
||||
if err != nil {
|
||||
log.Warn("unable to create web cache client", err)
|
||||
}
|
||||
reasonableDurationCacheClient, err := cache.NewClient(
|
||||
cache.ClientWithAdapter(responseCache),
|
||||
cache.ClientWithTTL(8*time.Second),
|
||||
)
|
||||
if err != nil {
|
||||
log.Warn("unable to create web cache client", err)
|
||||
}
|
||||
longerDurationCacheClient, err := cache.NewClient(
|
||||
cache.ClientWithAdapter(responseCache),
|
||||
cache.ClientWithTTL(3*time.Minute),
|
||||
)
|
||||
if err != nil {
|
||||
log.Warn("unable to create web cache client", err)
|
||||
}
|
||||
// The primary web app.
|
||||
http.HandleFunc("/", controllers.IndexHandler)
|
||||
|
||||
@ -70,79 +35,41 @@ func Start() error {
|
||||
http.HandleFunc("/admin/", middleware.RequireAdminAuth(controllers.IndexHandler))
|
||||
|
||||
// Images
|
||||
http.HandleFunc("/thumbnail.jpg", func(rw http.ResponseWriter, r *http.Request) {
|
||||
superShortCacheClient.Middleware(http.HandlerFunc(controllers.GetThumbnail)).ServeHTTP(rw, r)
|
||||
})
|
||||
|
||||
http.HandleFunc("/preview.gif", func(rw http.ResponseWriter, r *http.Request) {
|
||||
superShortCacheClient.Middleware(http.HandlerFunc(controllers.GetPreview)).ServeHTTP(rw, r)
|
||||
})
|
||||
|
||||
http.HandleFunc("/logo", func(rw http.ResponseWriter, r *http.Request) {
|
||||
longerDurationCacheClient.Middleware(http.HandlerFunc(controllers.GetLogo)).ServeHTTP(rw, r)
|
||||
})
|
||||
http.HandleFunc("/thumbnail.jpg", controllers.GetThumbnail)
|
||||
http.HandleFunc("/preview.gif", controllers.GetPreview)
|
||||
http.HandleFunc("/logo", controllers.GetLogo)
|
||||
|
||||
// Custom Javascript
|
||||
http.HandleFunc("/customjavascript", func(rw http.ResponseWriter, r *http.Request) {
|
||||
longerDurationCacheClient.Middleware(http.HandlerFunc(controllers.ServeCustomJavascript)).ServeHTTP(rw, r)
|
||||
})
|
||||
http.HandleFunc("/customjavascript", controllers.ServeCustomJavascript)
|
||||
|
||||
// Return a single emoji image.
|
||||
http.HandleFunc(config.EmojiDir, func(rw http.ResponseWriter, r *http.Request) {
|
||||
longerDurationCacheClient.Middleware(http.HandlerFunc(controllers.GetCustomEmojiImage)).ServeHTTP(rw, r)
|
||||
})
|
||||
http.HandleFunc(config.EmojiDir, controllers.GetCustomEmojiImage)
|
||||
|
||||
// return the logo
|
||||
|
||||
// return a logo that's compatible with external social networks
|
||||
http.HandleFunc("/logo/external", func(rw http.ResponseWriter, r *http.Request) {
|
||||
longerDurationCacheClient.Middleware(http.HandlerFunc(controllers.GetCompatibleLogo)).ServeHTTP(rw, r)
|
||||
})
|
||||
http.HandleFunc("/logo/external", controllers.GetCompatibleLogo)
|
||||
|
||||
// robots.txt
|
||||
http.HandleFunc("/robots.txt", func(rw http.ResponseWriter, r *http.Request) {
|
||||
longerDurationCacheClient.Middleware(http.HandlerFunc(controllers.GetRobotsDotTxt)).ServeHTTP(rw, r)
|
||||
})
|
||||
http.HandleFunc("/robots.txt", controllers.GetRobotsDotTxt)
|
||||
|
||||
// status of the system
|
||||
if enableCache {
|
||||
http.HandleFunc("/api/status", func(rw http.ResponseWriter, r *http.Request) {
|
||||
superShortCacheClient.Middleware(http.HandlerFunc(controllers.GetStatus)).ServeHTTP(rw, r)
|
||||
})
|
||||
} else {
|
||||
http.HandleFunc("/api/status", controllers.GetStatus)
|
||||
}
|
||||
http.HandleFunc("/api/status", controllers.GetStatus)
|
||||
|
||||
// custom emoji supported in the chat
|
||||
http.HandleFunc("/api/emoji", func(rw http.ResponseWriter, r *http.Request) {
|
||||
reasonableDurationCacheClient.Middleware(http.HandlerFunc(controllers.GetCustomEmojiList)).ServeHTTP(rw, r)
|
||||
})
|
||||
http.HandleFunc("/api/emoji", controllers.GetCustomEmojiList)
|
||||
|
||||
// chat rest api
|
||||
if enableCache {
|
||||
http.HandleFunc("/api/chat", func(rw http.ResponseWriter, r *http.Request) {
|
||||
superShortCacheClient.Middleware(middleware.RequireUserAccessToken(controllers.GetChatMessages))
|
||||
})
|
||||
} else {
|
||||
http.HandleFunc("/api/chat", middleware.RequireUserAccessToken(controllers.GetChatMessages))
|
||||
}
|
||||
http.HandleFunc("/api/chat", middleware.RequireUserAccessToken(controllers.GetChatMessages))
|
||||
|
||||
// web config api
|
||||
if enableCache {
|
||||
http.HandleFunc("/api/config", func(rw http.ResponseWriter, r *http.Request) {
|
||||
superShortCacheClient.Middleware(http.HandlerFunc(controllers.GetWebConfig)).ServeHTTP(rw, r)
|
||||
})
|
||||
} else {
|
||||
http.HandleFunc("/api/config", controllers.GetWebConfig)
|
||||
}
|
||||
http.HandleFunc("/api/config", controllers.GetWebConfig)
|
||||
|
||||
// return the YP protocol data
|
||||
http.HandleFunc("/api/yp", yp.GetYPResponse)
|
||||
|
||||
// list of all social platforms
|
||||
http.HandleFunc("/api/socialplatforms", func(rw http.ResponseWriter, r *http.Request) {
|
||||
reasonableDurationCacheClient.Middleware(http.HandlerFunc(controllers.GetAllSocialPlatforms)).ServeHTTP(rw, r)
|
||||
})
|
||||
http.HandleFunc("/api/socialplatforms", controllers.GetAllSocialPlatforms)
|
||||
|
||||
// return the list of video variants available
|
||||
http.HandleFunc("/api/video/variants", controllers.GetVideoStreamOutputVariants)
|
||||
@ -157,9 +84,7 @@ func Start() error {
|
||||
http.HandleFunc("/api/remotefollow", controllers.RemoteFollow)
|
||||
|
||||
// return followers
|
||||
http.HandleFunc("/api/followers", func(rw http.ResponseWriter, r *http.Request) {
|
||||
reasonableDurationCacheClient.Middleware(middleware.HandlePagination(controllers.GetFollowers)).ServeHTTP(rw, r)
|
||||
})
|
||||
http.HandleFunc("/api/followers", middleware.HandlePagination(controllers.GetFollowers))
|
||||
|
||||
// save client video playback metrics
|
||||
http.HandleFunc("/api/metrics/playback", controllers.ReportPlaybackMetrics)
|
||||
|
||||
Reference in New Issue
Block a user