mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-28 21:21:40 -05:00
parent
0cae1cf828
commit
786f72302f
2 changed files with 13 additions and 2 deletions
|
@ -322,7 +322,7 @@ func (c *PageCollections) clearResourceCacheForPage(page *Page) {
|
||||||
first := page.Resources[0]
|
first := page.Resources[0]
|
||||||
dir := path.Dir(first.RelPermalink())
|
dir := path.Dir(first.RelPermalink())
|
||||||
dir = strings.TrimPrefix(dir, page.LanguagePrefix())
|
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)
|
page.s.ResourceSpec.DeleteCacheByPrefix(dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ type imageCache struct {
|
||||||
|
|
||||||
func (c *imageCache) isInCache(key string) bool {
|
func (c *imageCache) isInCache(key string) bool {
|
||||||
c.mu.RLock()
|
c.mu.RLock()
|
||||||
_, found := c.store[key]
|
_, found := c.store[c.normalizeKey(key)]
|
||||||
c.mu.RUnlock()
|
c.mu.RUnlock()
|
||||||
return found
|
return found
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ func (c *imageCache) isInCache(key string) bool {
|
||||||
func (c *imageCache) deleteByPrefix(prefix string) {
|
func (c *imageCache) deleteByPrefix(prefix string) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
prefix = c.normalizeKey(prefix)
|
||||||
for k := range c.store {
|
for k := range c.store {
|
||||||
if strings.HasPrefix(k, prefix) {
|
if strings.HasPrefix(k, prefix) {
|
||||||
delete(c.store, k)
|
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() {
|
func (c *imageCache) clear() {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
|
Loading…
Reference in a new issue