diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-07-11 19:23:22 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-07-11 20:40:04 +0200 |
commit | 6b6dcb44a014699c289bf32fe57d4c4216777be0 (patch) | |
tree | ee7c4a831be73ec9e1656690550bccb8ee913f97 /tpl | |
parent | d96f2a460f58e91d8f6253a489d4879acfec6916 (diff) |
Flush partialCached cache on rebuilds
Fixes #4931
Diffstat (limited to 'tpl')
-rw-r--r-- | tpl/partials/init_test.go | 4 | ||||
-rw-r--r-- | tpl/partials/partials.go | 16 |
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, |