Skip to content

Commit

Permalink
tpl: Use hash for cache key
Browse files Browse the repository at this point in the history
Use a hash for the cache key, to fix 'file name too long' errors when retreiving from long urls

Fixes #3690
  • Loading branch information
RealOrangeOne authored and bep committed Jul 21, 2017
1 parent dbe6397 commit 6cd33f6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tpl/data/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
package data

import (
"crypto/md5"
"encoding/hex"
"errors"
"net/url"
"sync"

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

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

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

0 comments on commit 6cd33f6

Please sign in to comment.