Deps: d,
layoutHandler: output.NewLayoutHandler(),
layoutsFs: d.BaseFs.Layouts.Fs,
- layoutTemplateCache: make(map[layoutCacheKey]tpl.Template),
+ layoutTemplateCache: make(map[layoutCacheKey]layoutCacheEntry),
templateUsageTracker: templateUsageTracker,
}
layoutHandler *output.LayoutHandler
- layoutTemplateCache map[layoutCacheKey]tpl.Template
+ layoutTemplateCache map[layoutCacheKey]layoutCacheEntry
layoutTemplateCacheMu sync.RWMutex
*deps.Deps
templateUsageTrackerMu sync.Mutex
}
+type layoutCacheEntry struct {
+ found bool
+ templ tpl.Template
+ err error
+}
+
// AddTemplate parses and adds a template to the collection.
// Templates with name prefixed with "_text" will be handled as plain
// text templates.
t.layoutTemplateCacheMu.RLock()
if cacheVal, found := t.layoutTemplateCache[key]; found {
t.layoutTemplateCacheMu.RUnlock()
- return cacheVal, true, nil
+ return cacheVal.templ, cacheVal.found, cacheVal.err
}
t.layoutTemplateCacheMu.RUnlock()
defer t.layoutTemplateCacheMu.Unlock()
templ, found, err := t.findLayout(d, f)
- if err == nil && found {
- t.layoutTemplateCache[key] = templ
- return templ, true, nil
- }
+ cacheVal := layoutCacheEntry{found: found, templ: templ, err: err}
+ t.layoutTemplateCache[key] = cacheVal
+ return cacheVal.templ, cacheVal.found, cacheVal.err
- return nil, false, err
}
// This currently only applies to shortcodes and what we get here is the