Can resources returned from a CefResourceHandler Be Cached?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Can resources returned from a CefResourceHandler Be Cached?

Postby Mayhew » Tue Mar 23, 2021 6:39 pm

I have a CefResourceHandler subclass that returns data from disk, usually media files like images and video. I would like the browser to cache the resources and verify its cached copy is up to date. I do have the cache folders setup properly and the browser does write files to the cache directories.

My resource handler does respond with all the correct header values like
Accept-Ranges: bytes
Cache-Control: no-cache, must-revalidate
Connection: keep-alive
Content-Length: 14653626
Content-Range: bytes 4521984-19175609/19175610
Content-Type: video/mp4
Date: Tue, 23 Mar 2021 23:36:44 GMT
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Last-Modified: Thu, 06 Aug 2020 20:44:24 GMT
pragma: no-cache

The problme is that the request headers received never contain the "if-modified-since" header to allow me to verify the modified time. Could this be a limitation of resource handlers in general or possibly a problem with the URL that is being invoked that the resource handler responds to? Just curious if this can be made to work or if I am wasting my time.
Mayhew
Expert
 
Posts: 303
Joined: Mon Apr 18, 2011 8:02 pm

Re: Can resources returned from a CefResourceHandler Be Cach

Postby fddima » Tue Mar 23, 2021 6:50 pm

Your response headers say do not cache via "pragma: no-cache" and "Cache-Control: no-cache, must-revalidate".

Regardless to this caching behavior needs rechecked anyway, i'm had some issues in past (many years ago), so no idea about current status.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: Can resources returned from a CefResourceHandler Be Cach

Postby Mayhew » Wed Mar 24, 2021 12:59 pm

The http spec https://developer.mozilla.org/en-US/doc ... TP/Caching states that no-cache means

Cache but revalidate
A cache will send the request to the origin server for validation before releasing a cached copy.


So I think in order to allow a request/response to be cached but force the browser to revalidate its freshness with the server you need Cache-Control: no-cache, must-revalidate.
Mayhew
Expert
 
Posts: 303
Joined: Mon Apr 18, 2011 8:02 pm

Re: Can resources returned from a CefResourceHandler Be Cach

Postby fddima » Wed Mar 24, 2021 2:43 pm

You are right.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 27 guests