From 17655cdf1b409521262d5d54eb19884d307c47ce Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Sat, 3 Feb 2018 23:37:05 +0100 Subject: Enable caching on assets and avatars (#3376) * Enable caching on assets and avatars Fixes #3323 * Only set avatar in user BeforeUpdate when there is no avatar set * add error checking after stat * gofmt * Change cache time for avatars to an hour --- routers/routes/routes.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'routers') diff --git a/routers/routes/routes.go b/routers/routes/routes.go index e51bfb946a..1d95bb4c76 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -7,6 +7,7 @@ package routes import ( "os" "path" + "time" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" @@ -53,21 +54,23 @@ func NewMacaron() *macaron.Macaron { } m.Use(public.Custom( &public.Options{ - SkipLogging: setting.DisableRouterLog, + SkipLogging: setting.DisableRouterLog, + ExpiresAfter: time.Hour * 6, }, )) m.Use(public.Static( &public.Options{ - Directory: path.Join(setting.StaticRootPath, "public"), - SkipLogging: setting.DisableRouterLog, + Directory: path.Join(setting.StaticRootPath, "public"), + SkipLogging: setting.DisableRouterLog, + ExpiresAfter: time.Hour * 6, }, )) - m.Use(macaron.Static( + m.Use(public.StaticHandler( setting.AvatarUploadPath, - macaron.StaticOptions{ - Prefix: "avatars", - SkipLogging: setting.DisableRouterLog, - ETag: true, + &public.Options{ + Prefix: "avatars", + SkipLogging: setting.DisableRouterLog, + ExpiresAfter: time.Hour * 6, }, )) -- cgit v1.2.3