Content adapters: caching

Following the reference example in the docs I’ve built a Hugo site using content from a Wordpress site via the REST API.

This works as intended on the first run. Both hugo server and hugo download the remote data and build/serve as expected.

On later rebuilds, no posts added to the WP site since the initial build are added. This seems to be a caching issue. The command hugo server --ignoreCache will fetch the updated posts.

As I recall this is done to avoid hammering an API on rebuilds, which is a sane choice. However, I’m not sure how to trigger a rebuild to fetch updates without using the --ignoreCache flag.

Is using the flag the expected behavior, or is there something I’m missing?

You can control how long the data is cached:
https://gohugo.io/getting-started/configuration/#configure-file-caches

For example, to evict the cache after 10 minutes:

[caches.getresource]
dir = ':cacheDir/:project'
maxAge = '10m'

You can change the cache location if you want to inspect and easily clear it. For example, to place the files in the resources directory in the root of your project:

[caches.getresource]
dir = ':resourceDir'
maxAge = '10m'
1 Like

Got it, thanks. I wasn’t sure if the config cache settings applied here.

You can also set a unique cache expiration for each resources.GetRemote call:
https://gohugo.io/functions/resources/getremote/#caching

So you could have a global cache expiration of 168h (7 days), but expire calls to example.org/foo.json every hour.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.