clearing htmlViewer caches by code

Hello,
is there a way to clear by code the caches folder created when calling a htmlViewer object?
The following code does nothing until the app doesn’t quit and it is launched again.
Since the htmlViewer is in a window called by a main window, I thought that after closing the window containing the htmlViewer, I’d be able to clear the caches.
But as I said, to have the code work, I have to quit the app, relaunch it, and open the window containing the Viewer.

BTW: the code below uses two loops, because I wanted to test if at least one of the two loops would work. Indeed, at present, the first loop is not necessary; fsCachedData folder’s files get automatically deleted when the app is launched anew as explained above.

Suggestions will be appreciated. Thank you.
OS 10.11.5 Xojo 2016v1.1

dim f as FolderItem = SpecialFolder.UserLibrary
if f <> nil and f.Exists then
f = f.Child(“Caches”)
if f <> nil and f.Exists then
f = f.Child(“com.myCompany.myApplication”)
if f <> nil and f.Exists then
dim temp() as FolderItem
for i as Integer = 1 to f.Count
dim ff as FolderItem = f.Item(i)
if ff.Directory then//delete fsCachedData folder’s files
for k as Integer = 1 to ff.Count
temp.Append ff.Item(k)
next
end if
next
for Each h as FolderItem in temp
h.Delete
next
ReDim temp(-1)
for i as Integer = 1 to f.Count//delete remaining files
temp.Append f.Item(i)
next
for Each h as FolderItem in temp
h.Delete
next
end if
end if
end if

The code pasted above did not preserve indentation. I paste it again, hoping indentation is preserved.

dim f as FolderItem = SpecialFolder.UserLibrary
if f <> nil and f.Exists then
f = f.Child(“Caches”)
if f <> nil and f.Exists then
f = f.Child(“com.myCompany.myApplication”)
if f <> nil and f.Exists then
dim temp() as FolderItem
for i as Integer = 1 to f.Count
dim ff as FolderItem = f.Item(i)
if ff.Directory then//delete fsCachedData folder’s files
for k as Integer = 1 to ff.Count
temp.Append ff.Item(k)
next
end if
next
for Each h as FolderItem in temp
h.Delete
next
ReDim temp(-1)
for i as Integer = 1 to f.Count//delete remaining files
temp.Append f.Item(i)
next
for Each h as FolderItem in temp
h.Delete
next
end if
end if
end if

[quote=275426:@Carlo Rubini]The code pasted above did not preserve indentation. I paste it again, hoping indentation is preserved.
[/quote]

You must click the Code icon above the edit area to obtain this :

dim f as FolderItem = SpecialFolder.UserLibrary if f <> nil and f.Exists then f = f.Child("Caches") if f <> nil and f.Exists then f = f.Child("com.myCompany.myApplication") if f <> nil and f.Exists then dim temp() as FolderItem for i as Integer = 1 to f.Count dim ff as FolderItem = f.Item(i) if ff.Directory then//delete fsCachedData folder's files for k as Integer = 1 to ff.Count temp.Append ff.Item(k) next end if next for Each h as FolderItem in temp h.Delete next ReDim temp(-1) for i as Integer = 1 to f.Count//delete remaining files temp.Append f.Item(i) next for Each h as FolderItem in temp h.Delete next end if end if end if

Thank you, Michel.

What happens if you close the html viewer, clear the caches, and create a new one?

Sorry for being late in answering: Internet connection was down.
Closing the window containing the html viewer, clearing the caches, and reopening the window containing the htmlViewer the content of caches is not deleted. Upon closing the window, I even called htmlViewer1.close, but it makes no difference.
Thanks.

Can we use ‘’ in the header of the html pages before loading into the htmlviewer so that does not cache at all instead of clearing the cache?

@Richard Duke Actually my aim is to clear the caches.

so u still want the page to cache… yet want a button to clear the cache.

I don’t really get what you want to achieve with the code you posted.

You could explore the JavaScript solutions discussed here https://duckduckgo.com/?q=javascript+clear+browser+cache&ia=qa

However,since apparently relaunching the app does the trick, maybe the simplest way to go is to use a helper to display the window where the HTMLViewer stands, so you can quit and relaunch it at will.

@Richard and Michel: Since all browsers offer the option to clear the cache, I thought it good to offer users the same option.
Thank you for the link to duckduckgo: I’ll have a look at it.

The LR is your friend http://documentation.xojo.com/index.php/SpecialFolder

SpecialFolder.InternetCache.launch msgbox SpecialFolder.InternetCache.ShellPath

It is possible that in a sandboxed app these files be stored in the app container, so you will have access to them.

Otherwise, if they remain in ~/Library/Caches, you will not be able to access them from a sandboxed app.

@Michel Bujardet Ah! I usually try to do my homework before posting to the forum.
Thank you, Michel.