diff options
author | Bjørn Erik Pedersen <[email protected]> | 2019-09-03 10:36:09 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2019-09-03 18:38:57 +0200 |
commit | 8624b9fe9eb81aeb884d36311fb6f85fed98aa43 (patch) | |
tree | 830fcb271584065cc6577c17808ade64cdb68b88 /resources/image_cache.go | |
parent | 018494f363a32b9e4d3622da6842bc3e59b420b2 (diff) | |
download | hugo-8624b9fe9eb81aeb884d36311fb6f85fed98aa43.tar.gz hugo-8624b9fe9eb81aeb884d36311fb6f85fed98aa43.zip |
Cache processed images by their source path
Fixes #6269
Diffstat (limited to 'resources/image_cache.go')
-rw-r--r-- | resources/image_cache.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/resources/image_cache.go b/resources/image_cache.go index 3a9e3c2c5..9192a8e43 100644 --- a/resources/image_cache.go +++ b/resources/image_cache.go @@ -73,11 +73,18 @@ func (c *imageCache) getOrCreate( parent *imageResource, conf images.ImageConfig, createImage func() (*imageResource, image.Image, error)) (*resourceAdapter, error) { relTarget := parent.relTargetPathFromConfig(conf) - key := parent.relTargetPathForRel(relTarget.path(), false, false, false) + memKey := parent.relTargetPathForRel(relTarget.path(), false, false, false) + + // For the file cache we want to generate and store it once if possible. + fileKeyPath := relTarget + if fi := parent.root.getFileInfo(); fi != nil { + fileKeyPath.dir = filepath.ToSlash(filepath.Dir(fi.Meta().Path())) + } + fileKey := fileKeyPath.path() // First check the in-memory store, then the disk. c.mu.RLock() - cachedImage, found := c.store[key] + cachedImage, found := c.store[memKey] c.mu.RUnlock() if found { @@ -133,7 +140,7 @@ func (c *imageCache) getOrCreate( // but the count of processed image variations for this site. c.pathSpec.ProcessingStats.Incr(&c.pathSpec.ProcessingStats.ProcessedImages) - _, err := c.fileCache.ReadOrCreate(key, read, create) + _, err := c.fileCache.ReadOrCreate(fileKey, read, create) if err != nil { return nil, err } @@ -142,13 +149,13 @@ func (c *imageCache) getOrCreate( img.setSourceFs(c.fileCache.Fs) c.mu.Lock() - if cachedImage, found = c.store[key]; found { + if cachedImage, found = c.store[memKey]; found { c.mu.Unlock() return cachedImage, nil } imgAdapter := newResourceAdapter(parent.getSpec(), true, img) - c.store[key] = imgAdapter + c.store[memKey] = imgAdapter c.mu.Unlock() return imgAdapter, nil |