Skip to content

Commit

Permalink
tpl/transform: Include options in cache key
Browse files Browse the repository at this point in the history
See #5555
  • Loading branch information
bep committed Dec 23, 2018
1 parent 62d031a commit be58c7b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions parser/metadecoders/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/csv"
"encoding/json"
"fmt"
"strings"

"github.com/gohugoio/hugo/common/herrors"

Expand All @@ -39,6 +40,14 @@ type Decoder struct {
Comment rune
}

// OptionsKey is used in cache keys.
func (d Decoder) OptionsKey() string {
var sb strings.Builder
sb.WriteRune(d.Delimiter)
sb.WriteRune(d.Comment)
return sb.String()
}

// Default is a Decoder in its default configuration.
var Default = Decoder{
Delimiter: ',',
Expand Down
4 changes: 4 additions & 0 deletions tpl/transform/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func (ns *Namespace) Unmarshal(args ...interface{}) (interface{}, error) {
return nil, errors.New("no Key set in Resource")
}

if decoder != metadecoders.Default {
key += decoder.OptionsKey()
}

return ns.cache.GetOrCreate(key, func() (interface{}, error) {
f := metadecoders.FormatFromMediaType(r.MediaType())
if f == "" {
Expand Down

0 comments on commit be58c7b

Please sign in to comment.