So... You can't clear the cache, the settings flags are broken, and scheme handlers don't intercept?

2,281 views
Skip to first unread message

Rob Christ

unread,
Mar 4, 2014, 6:17:59 PM3/4/14
to cefs...@googlegroups.com
**Summary at end**
I'm trying to make sure that every time a user views a website, they do so completely fresh, and do not rely on cached _anything_.  

I started by setting:
var browserSettings = new BrowserSettings()
                {
                    PageCacheDisabled = true,
                    ApplicationCacheDisabled = true
                };

But that appears to have had no effect on, well, anything.  Are these settings just broken?

I have tried setting the Settings.CachePath to a value, and then before every webView.Load deleting all files from that directory, but again, the browser appears to use cached data.

So my next idea was that if I could just intercept the response headers for each request, I could set them to include no caching headers.  I looked in OnBeforeBrowser, but you can't access the response there.

So I set up a custom scheme handler for "http", where you _can_ access the response object, but apparently that is because you are expected to supply one?  I just want to intercept the normal one, not completely replace it from scratch.  I'm at the point where I'm contemplating implementing my own HttpRequest/Response every single time ProcessRequestAsync is called (so that I can set the response headers to do not cache when they arrive back), but surely there's a better way?

Note: I am able to delete cookies via the CEF.VisitAllCookies, which is nice.

**So to summarize**
1) How can I clear the cache?  Are the browser settings flags just broken?
2) Can I intercept http responses in a custom scheme handler, WITHOUT reimplementing normal functionality?  just an intercept of the response, not a replace? 
2a) If no to #2, can anyone thing of a workaround?
3) So is it just not possible to clear the cache between browser calls? 

CefSharp 1.25.7, Winform

Rob Christ

unread,
Mar 5, 2014, 11:06:01 AM3/5/14
to cefs...@googlegroups.com
So I've been looking into this more, and it seems that CEF itself simply doesn't handle caching, and yeah, depending on what OS you're on, those browser settings flags don't work for everybody.  So it seems like those issues are pretty far upstream.
There's a pretty good thread detailing Adobe's problems with CEF on this topic here: https://github.com/adobe/brackets/issues/1744.  They seem to have implemented their own controllable cache, and used sockets to write/release data from it directly.  http://blog.openfin.co/post/56138831504/why-weve-moved-on-from-chromium-embedded-framework <- another company that left CEF based on this, and a few other missing features.

Setting the response headers in the OnResourceResponse event doesn't seem to have any effect, unfortunately.

Rob Christ

unread,
Mar 5, 2014, 11:06:09 AM3/5/14
to cefs...@googlegroups.com

**But creating an HTTP scheme handler did work!!!!!!!!!!** HUZZAH

public bool ProcessRequestAsync(IRequest request, SchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback)
        {
            try
            {
                WebClient client = new WebClient();
                response.MimeType = "text/html";
                response.ResponseStream = client.OpenRead(request.Url);
            }
            catch (WebException ex)
            {
                var webResponse = ex.Response as HttpWebResponse;
                if (webResponse != null)
                {
                    response.StatusCode = (int)(webResponse.StatusCode);
                }
                else
                {
                    throw;    
                }
            }

            response.ResponseHeaders = new Dictionary<string, string>
                {
                    {"Cache-Control", "no-cache, no-store, must-revalidate"},
                    {"Pragma", "no-cache"},
                    {"Expires", "0"}
                };

            requestCompletedCallback();
            return true;
        }

Thanks for all your work all, I hope this thread helps someone else in the future.

Tyler Jones

unread,
Aug 18, 2015, 5:42:58 PM8/18/15
to CefSharp
Hi, I am needing to implement this same thing.  How do you create an HTTP scheme handler?  How does this class get used by the CEF browser?

Alex Maitland

unread,
Aug 18, 2015, 6:04:42 PM8/18/15
to CefSharp
Reply all
Reply to author
Forward
0 new messages