Ah yes, concurrency, sorry about that.
baseof.html
{{ with $h := site.Home }}
{{ if not ($h.Store.Get "books") }}
{{ $u :="https://www.example.com/tests/data/books.json" }}
{{ with resources.GetRemote $u }}
{{ with .Err }}
{{ errorf "%s" }}
{{ else }}
{{ $h.Store.Set "books" (unmarshal .) }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote data at %s" $u }}
{{ end }}
{{ end }}
{{ end }}
So, we do the above on every page, but skip if we find the Store
value on the home page. Due to concurrency and Hugo’s speed, the code above will be executed more than once. But once the Store
has been written, subsequent pages won’t try again.
Testing a 1000 page site, the code above was executed between 2 and 8 times (tested it about 10 times). This is similar to what happens when you use partialCached
, and is expected.