Added cache options and config.
This commit is contained in:
parent
bccb538d19
commit
e499257686
3 changed files with 10 additions and 1 deletions
|
|
@ -43,6 +43,10 @@ type CacheConfig struct {
|
||||||
Hostname string `env:"CACHE_HOSTNAME,default=localhost"`
|
Hostname string `env:"CACHE_HOSTNAME,default=localhost"`
|
||||||
Port uint16 `env:"CACHE_PORT,default=6379"`
|
Port uint16 `env:"CACHE_PORT,default=6379"`
|
||||||
Password string `env:"CACHE_PASSWORD"`
|
Password string `env:"CACHE_PASSWORD"`
|
||||||
|
MaxAge struct {
|
||||||
|
StaticFile int `env:"CACHE_MAX_AGE_STATIC_FILE,default=15552000"`
|
||||||
|
Page int `env:"CACHE_STATIC_FILE_MAX_AGE,default=86400"`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetConfig loads and returns application configuration
|
// GetConfig loads and returns application configuration
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,11 @@ type Page struct {
|
||||||
}
|
}
|
||||||
Pager pager.Pager
|
Pager pager.Pager
|
||||||
CSRF string
|
CSRF string
|
||||||
|
Cache struct {
|
||||||
|
Enabled bool
|
||||||
|
MaxAge int
|
||||||
|
Tags []string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPage(c echo.Context) Page {
|
func NewPage(c echo.Context) Page {
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ func BuildRouter(c *container.Container) {
|
||||||
// Static files with proper cache control
|
// Static files with proper cache control
|
||||||
// funcmap.File() should be used in templates to append a cache key to the URL in order to break cache
|
// funcmap.File() should be used in templates to append a cache key to the URL in order to break cache
|
||||||
// after each server restart
|
// after each server restart
|
||||||
c.Web.Group("", middleware.CacheControl(15552000)).
|
c.Web.Group("", middleware.CacheControl(c.Config.Cache.MaxAge.StaticFile)).
|
||||||
Static("/", StaticDir)
|
Static("/", StaticDir)
|
||||||
|
|
||||||
// Base controller
|
// Base controller
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue