aboutsummaryrefslogtreecommitdiffhomepage
path: root/config/allconfig
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-05-17 17:06:47 +0200
committerBjørn Erik Pedersen <[email protected]>2024-06-04 16:07:39 +0200
commit447108fed2842e264897659856e9fd9cdc32ca23 (patch)
tree53687693e04496919dd84266cc1edc16746101b0 /config/allconfig
parentc71e24af5172e230baa5f7dfa2078721cda38df4 (diff)
downloadhugo-447108fed2842e264897659856e9fd9cdc32ca23.tar.gz
hugo-447108fed2842e264897659856e9fd9cdc32ca23.zip
Add a HTTP cache for remote resources.
Fixes #12502 Closes #11891
Diffstat (limited to 'config/allconfig')
-rw-r--r--config/allconfig/allconfig.go12
-rw-r--r--config/allconfig/alldecoders.go14
-rw-r--r--config/allconfig/configlanguage.go2
3 files changed, 28 insertions, 0 deletions
diff --git a/config/allconfig/allconfig.go b/config/allconfig/allconfig.go
index 76153f5c0..5ff456d55 100644
--- a/config/allconfig/allconfig.go
+++ b/config/allconfig/allconfig.go
@@ -27,6 +27,7 @@ import (
"time"
"github.com/gohugoio/hugo/cache/filecache"
+ "github.com/gohugoio/hugo/cache/httpcache"
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/common/maps"
@@ -119,6 +120,10 @@ type Config struct {
// <docsmeta>{"identifiers": ["caches"] }</docsmeta>
Caches filecache.Configs `mapstructure:"-"`
+ // The httpcache configuration section contains HTTP-cache-related configuration options.
+ // <docsmeta>{"identifiers": ["httpcache"] }</docsmeta>
+ HTTPCache httpcache.Config `mapstructure:"-"`
+
// The markup configuration section contains markup-related configuration options.
// <docsmeta>{"identifiers": ["markup"] }</docsmeta>
Markup markup_config.Config `mapstructure:"-"`
@@ -359,6 +364,11 @@ func (c *Config) CompileConfig(logger loggers.Logger) error {
}
}
+ httpCache, err := c.HTTPCache.Compile()
+ if err != nil {
+ return err
+ }
+
c.C = &ConfigCompiled{
Timeout: timeout,
BaseURL: baseURL,
@@ -374,6 +384,7 @@ func (c *Config) CompileConfig(logger loggers.Logger) error {
SegmentFilter: c.Segments.Config.Get(func(s string) { logger.Warnf("Render segment %q not found in configuration", s) }, c.RootConfig.RenderSegments...),
MainSections: c.MainSections,
Clock: clock,
+ HTTPCache: httpCache,
transientErr: transientErr,
}
@@ -413,6 +424,7 @@ type ConfigCompiled struct {
SegmentFilter segments.SegmentFilter
MainSections []string
Clock time.Time
+ HTTPCache httpcache.ConfigCompiled
// This is set to the last transient error found during config compilation.
// With themes/modules we compute the configuration in multiple passes, and
diff --git a/config/allconfig/alldecoders.go b/config/allconfig/alldecoders.go
index 7d968e4ad..fc033821e 100644
--- a/config/allconfig/alldecoders.go
+++ b/config/allconfig/alldecoders.go
@@ -18,6 +18,8 @@ import (
"strings"
"github.com/gohugoio/hugo/cache/filecache"
+
+ "github.com/gohugoio/hugo/cache/httpcache"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/common/types"
"github.com/gohugoio/hugo/config"
@@ -96,6 +98,18 @@ var allDecoderSetups = map[string]decodeWeight{
return err
},
},
+ "httpcache": {
+ key: "httpcache",
+ decode: func(d decodeWeight, p decodeConfig) error {
+ var err error
+ p.c.HTTPCache, err = httpcache.DecodeConfig(p.bcfg, p.p.GetStringMap(d.key))
+ if p.c.IgnoreCache {
+ p.c.HTTPCache.Cache.For.Excludes = []string{"**"}
+ p.c.HTTPCache.Cache.For.Includes = []string{}
+ }
+ return err
+ },
+ },
"build": {
key: "build",
decode: func(d decodeWeight, p decodeConfig) error {
diff --git a/config/allconfig/configlanguage.go b/config/allconfig/configlanguage.go
index a215fb5e4..1d2cb5ce3 100644
--- a/config/allconfig/configlanguage.go
+++ b/config/allconfig/configlanguage.go
@@ -173,6 +173,8 @@ func (c ConfigLanguage) GetConfigSection(s string) any {
return c.m.Modules
case "deployment":
return c.config.Deployment
+ case "httpCacheCompiled":
+ return c.config.C.HTTPCache
default:
panic("not implemented: " + s)
}