summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2018-07-29 14:26:45 +0200
committerBjørn Erik Pedersen <[email protected]>2018-07-29 14:26:45 +0200
commit786f72302f65580ca8d1df2132a7756584539ea0 (patch)
tree0bbf7b6135c6d2c16dce4bdafa6d6d5a13ba69cd
parent0cae1cf8286b128295057d076c479c929f0febb3 (diff)
downloadhugo-786f72302f65580ca8d1df2132a7756584539ea0.tar.gz
hugo-786f72302f65580ca8d1df2132a7756584539ea0.zip
Fix image cache eviction for sites with subdir in baseURL
Fixes #5006
-rw-r--r--hugolib/page_collections.go2
-rw-r--r--resource/image_cache.go13
2 files changed, 13 insertions, 2 deletions
diff --git a/hugolib/page_collections.go b/hugolib/page_collections.go
index d99857aec..2b2cfed0f 100644
--- a/hugolib/page_collections.go
+++ b/hugolib/page_collections.go
@@ -322,7 +322,7 @@ func (c *PageCollections) clearResourceCacheForPage(page *Page) {
first := page.Resources[0]
dir := path.Dir(first.RelPermalink())
dir = strings.TrimPrefix(dir, page.LanguagePrefix())
- // This is done to keep the memory usage in check when doing live reloads.
+ dir = strings.TrimPrefix(dir, page.s.BaseURL.Path())
page.s.ResourceSpec.DeleteCacheByPrefix(dir)
}
}
diff --git a/resource/image_cache.go b/resource/image_cache.go
index 4fb45c17f..e5149e7a2 100644
--- a/resource/image_cache.go
+++ b/resource/image_cache.go
@@ -33,7 +33,7 @@ type imageCache struct {
func (c *imageCache) isInCache(key string) bool {
c.mu.RLock()
- _, found := c.store[key]
+ _, found := c.store[c.normalizeKey(key)]
c.mu.RUnlock()
return found
}
@@ -41,6 +41,7 @@ func (c *imageCache) isInCache(key string) bool {
func (c *imageCache) deleteByPrefix(prefix string) {
c.mu.Lock()
defer c.mu.Unlock()
+ prefix = c.normalizeKey(prefix)
for k := range c.store {
if strings.HasPrefix(k, prefix) {
delete(c.store, k)
@@ -48,6 +49,16 @@ func (c *imageCache) deleteByPrefix(prefix string) {
}
}
+func (c *imageCache) normalizeKey(key string) string {
+ // It is a path with Unix style slashes and it always starts with a leading slash.
+ key = filepath.ToSlash(key)
+ if !strings.HasPrefix(key, "/") {
+ key = "/" + key
+ }
+
+ return key
+}
+
func (c *imageCache) clear() {
c.mu.Lock()
defer c.mu.Unlock()