Page 1 of 1

Different cache folder

Posted: Thu May 04, 2023 1:03 am
by alpires2000
Hi Salvador,

I need to configure a different cache folder for each instance of the form so I put these lines in the OnCreate event.

Code: Select all

GlobalWebView2Loader := TWVLoader.create(self);
GlobalWebView2Loader.UserDataFolder := ExtractFileDir(Application.ExeName) +
  '\Cache'+inttostr(lista_id);
GlobalWebView2Loader.StartWebView2;
Where list_id is a parameter received by the form

Apparently it worked but when I instantiate two or more forms and then close the forms and then the program, a memory leak occurs as shown in the attached image.

In CEF4 I use:

Code: Select all

TempContext := TCefRequestContextRef.New(ExtractFilePath(application.ExeName) + 'cache\cache' + inttostr(lista_id),'', '', false, false, false)
Any idea how can I do this in WebView4?

Re: Different cache folder

Posted: Thu May 04, 2023 2:31 am
by alpires2000
Hi Salvador, I found this way:

Code: Select all

    WVBrowser1.ProfileName := 'cache' + inttostr(lista_id);
    WVBrowser1.CreateBrowser(WVWindowParent1.Handle);
is this correct?

Re: Different cache folder

Posted: Sat May 06, 2023 8:29 am
by salvadordf
alpires2000 wrote: Thu May 04, 2023 2:31 am Hi Salvador, I found this way:

Code: Select all

    WVBrowser1.ProfileName := 'cache' + inttostr(lista_id);
    WVBrowser1.CreateBrowser(WVWindowParent1.Handle);
is this correct?
Yes, that's correct. Using a different profile name will create a different profile directory path on disk.
https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2controlleroptions?view=webview2-1.0.1722.45#get_profilename