Cache deletion

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.

Cache deletion

Postby Drawknob » Tue Jul 29, 2014 1:14 pm

As there seems to be no functionality to clear cache, I've tried simply deleting the files in the cache folder (running on Windows, without forced deletion, so that files to which there are open handles don't get deleted). However, this seems to cause invalid state even if all CefBrowser have been closed when I do this. Is it only safe only safe to do after CEF is fully shut down? How, then, can one implement functionality that is equivalent to clearing the cache of a regular, non-CEF browser while it is running? One thought I had is to try to ReloadIgnoreCache() after every first LoadURL() of a URL that had been loaded from the time the browser was started with empty cache, and the cache was manually cleared during runtime. But this seems very complicated and I don't know if it would even work. What's the best approach? I don't want to turn off the cache, but I do need to be able to clear it during specific times because I've come across a number of instances where state of interactive sites wasn't just stored in the cookies but also uses web storage etc.
Drawknob
Techie
 
Posts: 24
Joined: Wed Mar 05, 2014 3:22 pm

Re: Cache deletion

Postby magreenblatt » Tue Aug 05, 2014 4:36 am

You cannot safely delete the cache folder while CEF is loaded. If you want to reload without using the cache use ReloadIgnoreCache.
magreenblatt
Site Admin
 
Posts: 12407
Joined: Fri May 29, 2009 6:57 pm

Re: Cache deletion

Postby Drawknob » Tue Aug 05, 2014 6:45 pm

So when in Chrome I do "Clear browsing data", how does that work?
Drawknob
Techie
 
Posts: 24
Joined: Wed Mar 05, 2014 3:22 pm

Re: Cache deletion

Postby magreenblatt » Wed Aug 06, 2014 3:46 am

Drawknob wrote:So when in Chrome I do "Clear browsing data", how does that work?

Good question :). If you find out how that works perhaps we can do something similar in CEF.
magreenblatt
Site Admin
 
Posts: 12407
Joined: Fri May 29, 2009 6:57 pm

Re: Cache deletion

Postby PolesApart » Tue Oct 06, 2015 7:15 am

Is there currently any lights on doing this?
PolesApart
Mentor
 
Posts: 73
Joined: Fri Dec 05, 2014 1:24 pm

Re: Cache deletion

Postby rjxray » Mon Sep 11, 2023 3:49 am

I too now have the need to clear cookies at runtime from a user request.
Searching in the forum I could only find this old topic.

Is there any new information on this?
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am

Re: Cache deletion

Postby rjxray » Mon Sep 11, 2023 4:14 am

OK, this does it
Code: Select all
   CefRefPtr<CefCookieManager> cookieManager = CefCookieManager::GetGlobalManager(nullptr);
   cookieManager->DeleteCookies("", "", nullptr);
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am

Re: Cache deletion

Postby ndesktop » Mon Sep 11, 2023 9:30 am

I'm erasing the full cache directory using OS calls after CefUninitialize (just before the return from WinMain). Additional solutions might involve a watcher executable launched from the browser, which does a WaitForSingleObject INFINITE on the browser process, and when the handle is signaled, nuke the cache directory.
Otherwise, the DeleteCookies works, if only the cookies are what needs to be cleared up.
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am

Re: Cache deletion

Postby rjxray » Mon Sep 11, 2023 10:28 am

I'm also clearing local storage and navigation history like this
Code: Select all
for (auto browser : browsers) {
   CefRefPtr<CefDictionaryValue> params = CefDictionaryValue::Create();
   params->SetString("origin", browser->getCurrentURL());
   params->SetString("storage_types", "local_storage");
   browser->getHost()->ExecuteDevToolsMethod(0, "Storage.clearDataForOrigin", params);
   params->Clear();
   browser->getHost()->ExecuteDevToolsMethod(0, "Page.resetNavigationHistory", params);
   browser->reload();
}
rjxray
Expert
 
Posts: 115
Joined: Wed Jun 07, 2017 4:31 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 29 guests