Skip to content

Commit

Permalink
refactor: improve Cache-Control header for /stats/summary
Browse files Browse the repository at this point in the history
  • Loading branch information
aofei committed Apr 28, 2021
1 parent 269b4f7 commit 31b1dc7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ var (
// getHeadMethods is an array contains the GET and HEAD methods.
getHeadMethods = []string{http.MethodGet, http.MethodHead}

// minutelyCachemanGas is used to manage the Cache-Control header.
minutelyCachemanGas = cacheman.Gas(cacheman.GasConfig{
Public: true,
MaxAge: 60,
SMaxAge: -1,
})

// hourlyCachemanGas is used to manage the Cache-Control header.
hourlyCachemanGas = cacheman.Gas(cacheman.GasConfig{
Public: true,
Expand Down Expand Up @@ -76,7 +83,7 @@ func init() {
}

if _, err := base.Cron.AddJob(
"*/10 * * * *", // Every 10 minutes
"* * * * *", // Every minute
cron.NewChain(
cron.SkipIfStillRunning(cron.DiscardLogger),
).Then(cron.FuncJob(func() {
Expand Down
2 changes: 1 addition & 1 deletion handler/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func init() {
getHeadMethods,
"/stats/summary",
hStatSummary,
hourlyCachemanGas,
minutelyCachemanGas,
)

base.Air.BATCH(
Expand Down

0 comments on commit 31b1dc7

Please sign in to comment.