Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HTTP cache mechanisms for efficient cache update #11891

Closed
nainformatique opened this issue Jan 15, 2024 · 3 comments
Closed

Use HTTP cache mechanisms for efficient cache update #11891

nainformatique opened this issue Jan 15, 2024 · 3 comments

Comments

@nainformatique
Copy link

Hello,
First thanks a lot for your work on hugo!

I am using a lot of remote content for a hugo website and I ran into two cache issues:

  • It seems that empty responses (4XX, 5XX or tcp failures?) are cached. A resource was unavailable temporary at build time (I don ̛t recall if it was 4XX, 5XX or tcp fail) and hugo cached the empty response.
  • I can set an expiration date for my cache. But neverchanging files or frequently changing ones will be updated at the same rate.

For bandwidth efficiency and up to date HTTP resources, hugo could:

  • Make a HEAD request to check if the online resource is newer than the cached one. (And update it if needed)
  • Use the cached resource if the online is down or unfetchable (and do not overwrite it with empty answer)

If this check took place after the current cache expiry system, it may not break any expected behavior?
Do you think this would be a helpful feature to add? If not I could try to do it within a function or partial.

Thanks for your time!

First proposed on discourse

@bep
Copy link
Member

bep commented Jan 15, 2024

It seems that empty responses (4XX, 5XX or tcp failures?) are cached. A resource was unavailable temporary at build time (I don ̛t recall if it was 4XX, 5XX or tcp fail) and hugo cached the empty response.

The only responses that gets cached are 200 and 404, which I think make sense in most situations.

@bep
Copy link
Member

bep commented Jan 15, 2024

Make a HEAD request to check if the online resource is newer than the cached one. (And update it if needed)

The file cache we use are relatively simple and we use the timestamps on the file to determine if it has expired. This works for that purpose, but I don't think it works for the above purpose.

I suspect that an Etag based approach would be simpler to implement, but I'm not totally sure.

@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
@bep bep added the Enhancement label Jun 4, 2024
@bep bep self-assigned this Jun 4, 2024
@bep bep modified the milestones: v0.125.0, v0.127.0 Jun 4, 2024
bep added a commit to bep/hugo that referenced this issue Jun 4, 2024
@bep bep closed this as completed in 447108f Jun 4, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants