From dd692c710ad202905df273d9c25e66d332476ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 21 Sep 2018 11:01:59 +0200 Subject: [PATCH] hugolib: Clear the page cache per render This is a slight performance optimization with no functional effect. See #5239 --- hugolib/pageCache.go | 6 ++++++ hugolib/site.go | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hugolib/pageCache.go b/hugolib/pageCache.go index 15598a4f0..485da4ba3 100644 --- a/hugolib/pageCache.go +++ b/hugolib/pageCache.go @@ -44,6 +44,12 @@ func newPageCache() *pageCache { return &pageCache{m: make(map[string][]pageCacheEntry)} } +func (c *pageCache) clear() { + c.Lock() + defer c.Unlock() + c.m = make(map[string][]pageCacheEntry) +} + // get/getP gets a Pages slice from the cache matching the given key and // all the provided Pages slices. // If none found in cache, a copy of the first slice is created. diff --git a/hugolib/site.go b/hugolib/site.go index 59f0a9002..14f51f978 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -1012,6 +1012,8 @@ func (s *Site) setupSitePages() { } func (s *Site) render(config *BuildCfg, outFormatIdx int) (err error) { + // Clear the global page cache. + spc.clear() if outFormatIdx == 0 { if err = s.preparePages(); err != nil { @@ -1514,8 +1516,6 @@ func (s *Site) resetBuildState() { s.expiredCount = 0 - spc = newPageCache() - for _, p := range s.rawAllPages { p.subSections = Pages{} p.parent = nil