Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbep <bjorn.erik.pedersen@gmail.com>2015-01-21 21:13:11 +0300
committerbep <bjorn.erik.pedersen@gmail.com>2015-01-21 21:13:11 +0300
commit878754c21f7b91310bd80b48a7e676b3b1071504 (patch)
treeb7ea539f60073ba1bc7f875e1f4cc7742936201d
parentc8f8f48e9600f733422180d50a97bb2deea8ba75 (diff)
Protect the innerShortCodeCache by a RW lock
-rw-r--r--hugolib/shortcode.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go
index 8743cc321..ff3eaeb89 100644
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -22,6 +22,7 @@ import (
"sort"
"strconv"
"strings"
+ "sync"
"github.com/spf13/hugo/helpers"
"github.com/spf13/hugo/tpl"
@@ -143,18 +144,28 @@ func ShortcodesHandle(stringToParse string, page *Page, t tpl.Template) string {
return string(tmpContent)
}
-var isInnerShortcodeCache = make(map[string]bool)
+var isInnerShortcodeCache = struct {
+ sync.RWMutex
+ m map[string]bool
+}{m: make(map[string]bool)}
// to avoid potential costly look-aheads for closing tags we look inside the template itself
// we could change the syntax to self-closing tags, but that would make users cry
// the value found is cached
func isInnerShortcode(t *template.Template) bool {
- if m, ok := isInnerShortcodeCache[t.Name()]; ok {
+ isInnerShortcodeCache.RLock()
+ m, ok := isInnerShortcodeCache.m[t.Name()]
+ isInnerShortcodeCache.RUnlock()
+
+ if ok {
return m
}
match, _ := regexp.MatchString("{{.*?\\.Inner.*?}}", t.Tree.Root.String())
- isInnerShortcodeCache[t.Name()] = match
+
+ isInnerShortcodeCache.Lock()
+ isInnerShortcodeCache.m[t.Name()] = match
+ isInnerShortcodeCache.Unlock()
return match
}