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:

For example, to evict the cache after 10 minutes:

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:

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:

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

1 Like

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