Skip to content

Commit

Permalink
hugolib: Clear the page cache per render
Browse files Browse the repository at this point in the history
This is a slight performance optimization with no functional effect.

See gohugoio#5239
  • Loading branch information
bep committed Sep 21, 2018
1 parent 549ba19 commit 4f330d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions hugolib/pageCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions hugolib/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1514,8 +1516,6 @@ func (s *Site) resetBuildState() {

s.expiredCount = 0

spc = newPageCache()

for _, p := range s.rawAllPages {
p.subSections = Pages{}
p.parent = nil
Expand Down

0 comments on commit 4f330d2

Please sign in to comment.