Skip to content

Commit

Permalink
Add DISABLE_CACHE flag
Browse files Browse the repository at this point in the history
  • Loading branch information
nexryai committed Jan 27, 2024
1 parent 05c891a commit b505389
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@ func main() {
app := fiber.New()

// キャッシュする
app.Use(cache.New(cache.Config{
ExpirationGenerator: func(c *fiber.Ctx, cfg *cache.Config) time.Duration {
// 15分
return time.Minute * 15
},
KeyGenerator: func(c *fiber.Ctx) string {
// パスが違ってもクエリが同じなら同じ内容
return utils.CopyString(c.Query("url"))
},
}))
if os.Getenv("DISABLE_CACHE") != "1" {
log.Info("Cache enabled")
app.Use(cache.New(cache.Config{
ExpirationGenerator: func(c *fiber.Ctx, cfg *cache.Config) time.Duration {
// 15分
return time.Minute * 15
},
KeyGenerator: func(c *fiber.Ctx) string {
// パスが違ってもクエリが同じなら同じ内容
return utils.CopyString(c.Query("url"))
},
}))
} else {
log.Warn("Cache disabled")
}

// ルーター
router.SummalyRouter(app)
Expand Down

0 comments on commit b505389

Please sign in to comment.