summaryrefslogtreecommitdiffstats
path: root/tpl
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-07-11 19:23:22 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-07-11 20:40:04 +0200
commit6b6dcb44a014699c289bf32fe57d4c4216777be0 (patch)
treeee7c4a831be73ec9e1656690550bccb8ee913f97 /tpl
parentd96f2a460f58e91d8f6253a489d4879acfec6916 (diff)
Flush partialCached cache on rebuilds
Fixes #4931
Diffstat (limited to 'tpl')
-rw-r--r--tpl/partials/init_test.go4
-rw-r--r--tpl/partials/partials.go16
2 files changed, 17 insertions, 3 deletions
diff --git a/tpl/partials/init_test.go b/tpl/partials/init_test.go
index ef284a826..4832e6b66 100644
--- a/tpl/partials/init_test.go
+++ b/tpl/partials/init_test.go
@@ -26,7 +26,9 @@ func TestInit(t *testing.T) {
var ns *internal.TemplateFuncsNamespace
for _, nsf := range internal.TemplateFuncsNamespaceRegistry {
- ns = nsf(&deps.Deps{})
+ ns = nsf(&deps.Deps{
+ BuildStartListeners: &deps.Listeners{},
+ })
if ns.Name == name {
found = true
break
diff --git a/tpl/partials/partials.go b/tpl/partials/partials.go
index 18b8d7ed6..266329721 100644
--- a/tpl/partials/partials.go
+++ b/tpl/partials/partials.go
@@ -34,18 +34,30 @@ type partialCache struct {
p map[string]interface{}
}
+func (p *partialCache) clear() {
+ p.Lock()
+ defer p.Unlock()
+ p.p = make(map[string]interface{})
+}
+
// New returns a new instance of the templates-namespaced template functions.
func New(deps *deps.Deps) *Namespace {
+ cache := &partialCache{p: make(map[string]interface{})}
+ deps.BuildStartListeners.Add(
+ func() {
+ cache.clear()
+ })
+
return &Namespace{
deps: deps,
- cachedPartials: partialCache{p: make(map[string]interface{})},
+ cachedPartials: cache,
}
}
// Namespace provides template functions for the "templates" namespace.
type Namespace struct {
deps *deps.Deps
- cachedPartials partialCache
+ cachedPartials *partialCache
}
// Include executes the named partial and returns either a string,