shithub: hugo

Download patch

ref: dd692c710ad202905df273d9c25e66d332476ac9
parent: ed4f1edbd729bf75af89879b76fbad931693cd67
author: Bjørn Erik Pedersen <[email protected]>
date: Fri Sep 21 07:01:59 EDT 2018

hugolib: Clear the page cache per render

This is a slight performance optimization with no functional effect.

See #5239

--- a/hugolib/pageCache.go
+++ b/hugolib/pageCache.go
@@ -44,6 +44,12 @@
 	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.
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -1012,6 +1012,8 @@
 }
 
 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 {
@@ -1513,8 +1515,6 @@
 	s.futureCount = 0
 
 	s.expiredCount = 0
-
-	spc = newPageCache()
 
 	for _, p := range s.rawAllPages {
 		p.subSections = Pages{}