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
This commit is contained in:
Morgan Bazalgette 2018-02-03 23:37:05 +01:00 committed by Lauris BH
parent 77f8bad2fb
commit 17655cdf1b
5 changed files with 155 additions and 34 deletions

View file

@ -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,
},
))