diff options
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, |