Skip to content

Commit 6cd33f6

Browse files
RealOrangeOnebep
authored andcommitted
tpl: Use hash for cache key
Use a hash for the cache key, to fix 'file name too long' errors when retreiving from long urls Fixes #3690
1 parent dbe6397 commit 6cd33f6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

‎tpl/data/cache.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
package data
1515

1616
import (
17+
"crypto/md5"
18+
"encoding/hex"
1719
"errors"
18-
"net/url"
1920
"sync"
2021

2122
"github.com/gohugoio/hugo/config"
@@ -27,7 +28,8 @@ var cacheMu sync.RWMutex
2728

2829
// getCacheFileID returns the cache ID for a string.
2930
func getCacheFileID(cfg config.Provider, id string) string {
30-
return cfg.GetString("cacheDir") + url.QueryEscape(id)
31+
hash := md5.Sum([]byte(id))
32+
return cfg.GetString("cacheDir") + hex.EncodeToString(hash[:])
3133
}
3234

3335
// getCache returns the content for an ID from the file cache or an error.

0 commit comments

Comments
 (0)