Skip to content

Commit

Permalink
cache certain GET endpoints (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
prettyirrelevant authored Jun 1, 2023
1 parent 31a6610 commit 7510901
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions kilishi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ func setupMiddlewares(app *fiber.App, cfg *config.Config) {
app.Use(recover.New())
app.Use(cache.New(cache.Config{
Expiration: 24 * time.Hour,
Methods: []string{fiber.MethodPost},
Methods: []string{fiber.MethodPost, fiber.MethodGet},
Next: func(c *fiber.Ctx) bool {
noCacheEndpoints := map[string]bool{"/api/v1/playlists": true, "/api/v1/auth/spotify/refresh": true}
if _, ok := noCacheEndpoints[c.Path()]; ok && c.Method() == fiber.MethodPost {
noCachePOSTEndpoints := map[string]bool{"/api/v1/playlists": true, "/api/v1/auth/spotify/refresh": true}
if _, ok := noCachePOSTEndpoints[c.Path()]; ok && c.Method() == fiber.MethodPost {
return true
}

noCacheGETEndpoints := map[string]bool{"/api/v1/auth/deezer/callback": true, "/api/v1/auth/spotify/callback": true, "/api/v1/ping": true}
if _, ok := noCacheGETEndpoints[c.Path()]; ok && c.Method() == fiber.MethodGet {
return true
}

Expand Down

0 comments on commit 7510901

Please sign in to comment.