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

Ensure better caching of redirected Blob URLs #2058

Merged
merged 3 commits into from
Dec 6, 2024

Conversation

idlira
Copy link
Contributor

@idlira idlira commented Dec 6, 2024

Description

VirtualDelivery URLs were marked to be cached very long. When the underlying file changed a new URL would redirect there, but external sources (varnish, browsers and so on) would have already cached the URL and will be calling the old redirected URL.

This change ensures that:

  1. Once a physical URL exists, we will always redirect
  2. The redirected URL will either be not cached at all, or cached to a maximum of 1h.

Note that physical URLs are not affected by this change and respect the caching times defined by the call or its storage space definitions.

Examples

  • Physical URL is indefinitely cached
> GET /dasd/p/tenants/74dd32864152cce6e57fde4f014f617f/M7CELNNL7JDT9UE7PHJ9GU2OD4/P0930KVRLNPL105N66RNCPAH2O HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.7.1
> Accept: */*
> 
* Request completely sent off
< HTTP/1.1 200 OK
< Content-Disposition: inline;filename="P0930KVRLNPL105N66RNCPAH2O";filename*=UTF-8''P0930KVRLNPL105N66RNCPAH2O
< Content-MD5: ZA06iGDNLyQv5nLsGIKgvg==
< ETag: 640d3a8860cd2f242fe672ec1882a0be
< X-Amz-Date: 20241206T121615Z
< x-amz-content-sha256: STREAMING-AWS4-HMAC-SHA256-PAYLOAD
< x-amz-decoded-content-length: 43997
< access-control-expose-headers: ETag
< date: Fri, 06 Dec 2024 12:29:49 GMT
< accept-ranges: bytes
< content-length: 43997
< content-type: application/octet-stream
< expires: Sat, 04 Jan 2025 23:00:01 GMT
< cache-control: public, max-age=2543412
< last-modified: Fri, 06 Dec 2024 12:16:15 GMT
< connection: keep-alive
< server: mbp-ili2.net
< P3P: CP="This site does not have a p3p policy."
< vary: origin
  • Redirect to the URL above (not cached)
> GET /dasd/v/tenants/5f1c86cf1db3307e4b688d28fa77759c/tenant-small/M7CELNNL7JDT9UE7PHJ9GU2OD4 HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.7.1
> Accept: */*
> 
* Request completely sent off
< HTTP/1.1 307 Temporary Redirect
< cache-control: no-cache, max-age=0
< last-modified: Fri, 06 Dec 2024 13:02:42 GMT
< connection: keep-alive
< server: mbp-ili2.net
< P3P: CP="This site does not have a p3p policy."
< vary: origin
< content-length: 0
< location: /dasd/p/tenants/74dd32864152cce6e57fde4f014f617f/M7CELNNL7JDT9UE7PHJ9GU2OD4/P0930KVRLNPL105N66RNCPAH2O
  • Redirect to URL above (cached)
> GET /dasd/cv/tenants/5f1c86cf1db3307e4b688d28fa77759c/tenant-small/M7CELNNL7JDT9UE7PHJ9GU2OD4 HTTP/1.1
> 
* Request completely sent off
< HTTP/1.1 307 Temporary Redirect
< date: Fri, 06 Dec 2024 12:26:13 GMT
< expires: Fri, 06 Dec 2024 13:26:13 GMT
< cache-control: public, max-age=3600
< last-modified: Fri, 06 Dec 2024 12:26:13 GMT
< connection: keep-alive
< server: mbp-ili2.net
< P3P: CP="This site does not have a p3p policy."
< vary: origin
< content-length: 0
< location: /dasd/p/tenants/74dd32864152cce6e57fde4f014f617f/M7CELNNL7JDT9UE7PHJ9GU2OD4/P0930KVRLNPL105N66RNCPAH2O

Additional Notes

Checklist

  • Code change has been tested and works locally
  • Code was formatted via IntelliJ and follows SonarLint & best practices

For better understanding the actual reason for an early return.

Besides, computeCacheDurationFromHash should only compute and not alter the response

Fixes: OX-11230
and sets caching appropriately: either we don't cache if the URL says so, or we cache it to a maximum or 1h, as the target location of the redirected URL might change.

Previously, we cached the redirect URL as long as the physical URL, and that is usually very long to infinite.

Fixes: OX-11230
@idlira idlira added 🧬 Enhancement Contains new features 🕔 Wait for sirius Needs new version from another sirius lib to work labels Dec 6, 2024
Fixes: OX-11230
@idlira idlira removed the 🕔 Wait for sirius Needs new version from another sirius lib to work label Dec 6, 2024
@idlira idlira merged commit 5424099 into develop Dec 6, 2024
4 checks passed
@idlira idlira deleted the ili/OX-11230-url-caching branch December 6, 2024 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧬 Enhancement Contains new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants