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

[Problem/Bug]: Webview2 cache not consistent, does not respect max-age or ETag #4687

Open
caymaynard opened this issue Jul 17, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@caymaynard
Copy link

caymaynard commented Jul 17, 2024

What happened?

I have a WebView 2 application with a request handler that can generate preview images, which are then served to the frontend as PNG files.
These files should be cached so that they are not regenerated if the URL is the same.

When handling the request in WebView2, I include a Cache-control header of the form
Cache-Control: private, must-revalidate, max-age=3600

I expect this to cache the image for an hour.

What I find though, is that the image is not cached for the entire period, WebView2 will make another request to this URL before an hour has passed.
It does not seem to follow a particular rule, the request does get cached, but it seems to rerun the request anyway.
This seems to happen after a few separate requests have been handled, the previous requests are removed from the cache.

I have also added an ETag header to the request, to verify if it is for an existing image. Even though I send this header in the request, the response never includes an equivalent 'If-None-Match' header.

I would expect WebView2 to only rerun the request when max-age has passed, and to include the 'If-None-Match' header to verify if the content is the same when the original request includes the ETag header.

Importance

Moderate. My app's user experience is affected, but still usable.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

126.0.2592.102

SDK Version

1.0.2151.40

Framework

Win32

Operating System

Windows 11

OS Version

No response

Repro steps

  1. Setup an add_WebResourceRequested handler inside WebView2 to catch a request.
  2. Request a resource from the frontend which matches the filter.
  3. In the handler, set a Cache-Control Header to 'private, must-revalidate, max-age=3600' and an ETag header to '123'.
  4. Repeat the request from the frontend multiple times for separate images.

Expected:
The first request goes to the handler, subsequent requests use the cache. The ETag is sent on any stale data as the 'If-None-Match' header.
Actual:
Some of the requests use the cache, but not all of them.

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

@caymaynard caymaynard added the bug Something isn't working label Jul 17, 2024
@RichieHindle
Copy link

I'm also seeing this problem. I'm using AddWebResourceRequestedFilter() to receive requests for images from the hosted page. The page contains dynamic content that references image URLs that are fulfilled by my filter. As I interact with the page, causing new dynamic content to be added to the DOM, I'm seeing frequent repeated requests for the same image URLs. Often these repeated requests arrive within seconds of each other.

Adding Cache-Control response headers has no effect.

(Also, like @caymaynard, I find that adding ETag response headers doesn't cause the subsequent requests to carry If-None-Match request headers, but even if it did, I'd rather not receive repeated requests at all.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants