Hi - a general question about getJSON 's data. I understand that:
getJSON will store its data under $TMPDIR/hugo_cache/projectname/filecache/getjson/ in a file with a uuid name like 7d6d5027480532086d04c13c997c3057.
you can force a re-download of this data by using the switch --ignoreCache on your hugo command, so taking that off will re-use whatever is there.
Instead of manually downloading some json file to data under the project, I converted to use getJSON.
When you use it in an index where the resulting files are few, running without --ignoreCache is not a problem. But when you put it in a single.html template, especially when there’s a lot of pages, you are looking at lots of API calls to re-get the same file.
What I’m wondering about is, while I can assign the getJSON result into a variable and use it on that page, can I “re-use” that variable on the single.html in some way? If I can, I can leave off --ignoreCache, let the data be downloaded newly by the index and then re-use it in the single.
If I could specify the location exactly without a random uuid, I could call it consistently across local and CI environments perhaps. It also looks like I can use getJSON on a local file so, that should be possible. However, is that uuid going to be referenceable between, say, local and a CI.
Is there a strategy for this? I hope someone might have wrestled with this previously.
I would think that once you set a Scratch variable within the context of a getJSON call, then its value should be available globally.
However if this is about a new project and if the remote content does not change, then consider storing the JSON files locally, so that you could avoid possible future problems with remote content going 404.
What I tend to do as a general thing is to use partialCached function with your own custom key. Remember that partials can 1) Return data (the return keyword) and 2) Can be inlined (so you can put them close to where you use them).