diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-08-13 13:35:04 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-08-13 19:09:46 +0300 |
commit | cd575023af846aa18ffa709f37bc70277e98cad3 (patch) | |
tree | b3eb6fcd3ab7b9073699df0486210cec00f877a1 /resources/resource_factories | |
parent | 6315098104ff80f8be6d5ae812835b4b4079582e (diff) |
Improve the server assets cache invalidation logic
Fixes #6199
Diffstat (limited to 'resources/resource_factories')
-rw-r--r-- | resources/resource_factories/bundler/bundler.go | 3 | ||||
-rw-r--r-- | resources/resource_factories/create/create.go | 23 |
2 files changed, 16 insertions, 10 deletions
diff --git a/resources/resource_factories/bundler/bundler.go b/resources/resource_factories/bundler/bundler.go index 6655ee5c3..c310efa33 100644 --- a/resources/resource_factories/bundler/bundler.go +++ b/resources/resource_factories/bundler/bundler.go @@ -18,6 +18,7 @@ import ( "bytes" "fmt" "io" + "path" "path/filepath" "github.com/gohugoio/hugo/common/hugio" @@ -66,7 +67,7 @@ func (r *multiReadSeekCloser) Close() error { // Concat concatenates the list of Resource objects. func (c *Client) Concat(targetPath string, r resource.Resources) (resource.Resource, error) { // The CACHE_OTHER will make sure this will be re-created and published on rebuilds. - return c.rs.ResourceCache.GetOrCreate(resources.CACHE_OTHER, targetPath, func() (resource.Resource, error) { + return c.rs.ResourceCache.GetOrCreate(path.Join(resources.CACHE_OTHER, targetPath), func() (resource.Resource, error) { var resolvedm media.Type // The given set of resources must be of the same Media Type. diff --git a/resources/resource_factories/create/create.go b/resources/resource_factories/create/create.go index e42843c75..23edf317e 100644 --- a/resources/resource_factories/create/create.go +++ b/resources/resource_factories/create/create.go @@ -18,6 +18,7 @@ package create import ( "path" "path/filepath" + "strings" "github.com/gohugoio/hugo/hugofs/glob" @@ -42,7 +43,7 @@ func New(rs *resources.Spec) *Client { // Get creates a new Resource by opening the given filename in the assets filesystem. func (c *Client) Get(filename string) (resource.Resource, error) { filename = filepath.Clean(filename) - return c.rs.ResourceCache.GetOrCreate(resources.ResourceKeyPartition(filename), filename, func() (resource.Resource, error) { + return c.rs.ResourceCache.GetOrCreate(resources.ResourceCacheKey(filename), func() (resource.Resource, error) { return c.rs.New(resources.ResourceSourceDescriptor{ Fs: c.rs.BaseFs.Assets.Fs, LazyPublish: true, @@ -66,18 +67,22 @@ func (c *Client) GetMatch(pattern string) (resource.Resource, error) { } func (c *Client) match(pattern string, firstOnly bool) (resource.Resources, error) { - var partition string + var name string if firstOnly { - partition = "__get-match" + name = "__get-match" } else { - partition = "__match" + name = "__match" } - // TODO(bep) match will be improved as part of https://github.com/gohugoio/hugo/issues/6199 - partition = path.Join(resources.CACHE_OTHER, partition) - key := glob.NormalizePath(pattern) + pattern = glob.NormalizePath(pattern) + partitions := glob.FilterGlobParts(strings.Split(pattern, "/")) + if len(partitions) == 0 { + partitions = []string{resources.CACHE_OTHER} + } + key := path.Join(name, path.Join(partitions...)) + key = path.Join(key, pattern) - return c.rs.ResourceCache.GetOrCreateResources(partition, key, func() (resource.Resources, error) { + return c.rs.ResourceCache.GetOrCreateResources(key, func() (resource.Resources, error) { var res resource.Resources handle := func(info hugofs.FileMetaInfo) (bool, error) { @@ -110,7 +115,7 @@ func (c *Client) match(pattern string, firstOnly bool) (resource.Resources, erro // FromString creates a new Resource from a string with the given relative target path. func (c *Client) FromString(targetPath, content string) (resource.Resource, error) { - return c.rs.ResourceCache.GetOrCreate(resources.CACHE_OTHER, targetPath, func() (resource.Resource, error) { + return c.rs.ResourceCache.GetOrCreate(path.Join(resources.CACHE_OTHER, targetPath), func() (resource.Resource, error) { return c.rs.New( resources.ResourceSourceDescriptor{ Fs: c.rs.FileCaches.AssetsCache().Fs, |