Where is cache control ?

AndyDroid2012

Member
Licensed User
Longtime User
I have written first version of a program which downloads mp3 files and simple web page text and graphics.

There is one mp3 and one "webpage" per topic in a dynamic listview which might grow to hundreds of topics eventually, Think of it as a dynamic multimedia database.

I looked at the cache for my app and its about 6Mb after only a few topics are read. Most users may only ever look at these topics once or twice. I fear that the cache could grow uncontrollably.

Can I clear the cache by b4a instruction ?

Also, where is this cache ? I looked in sdcard and cannot see my app name.
 

AndyDroid2012

Member
Licensed User
Longtime User
Thank you.
It reports "/data.data/testit.test/cache" and /data/ is a protected folder.
I read elsewhere that android OS is very capable of managing cache for each app, deleting as needed if ram is short.

So, I will not worry about it, at least for now.
 
Upvote 0

AndyDroid2012

Member
Licensed User
Longtime User
This started by noticing the cache was about 6Mb shown in Settings for the app.
I then wondered how much it would grow, and now read on internet that android OS will manage it unassisted. However following your advice I added a button
and discovered folders

webviewCacheChromium

and
webviewCacheChromiumStaging which was empty.


B4X:
Sub Button4_Click
Listview1.Clear 
Dim List1 As List 
Dim file1 As String 
Dim n As Int

List11 = File.ListFiles(File.DirInternalCache & "/webviewCacheChromium") 
    For n = 0 To List1.Size-1
    file1 = List1.Get(n)
        Listview1.AddSingleLine(file1)
  Next
 
WebView1.LoadURL(File.DirInternalCache & "/webviewCacheChromium/data_0")
       WebView1.Visible = True
End Sub

What came back in the Listview contents for File.DirInternalCache & "/webviewCacheChromium

was these four entries

index
data_0
data_1
data_2
data_3


none of which are folders but objects of sorts, but attempting to put any of them into a webview for example gets "webpage not available"
So what are they ?
The content I was bringing down from my server was simple html and images and an mp3 audio.

Whats being cached ?

Now I am also wondering about offline functionality and realize that caching could be used if I knew what these objects were - or do I need to program save the downloads using the Cache Library ?
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
and now read on internet that android OS will manage it unassisted.

It just clears the cache folder when it needs some space for other apps. It's the most basic cache management.

...was these four entries

index
data_0
data_1
data_2
data_3
...

So what are they ?

The cache data of Chrome. If your cache content is managed by a web browser, you don't need to worry about it.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
You can use WebViewExtras and it's clearCache method to clear the WebView cache.

The WebView uses an SQLite database to manage cached items.
The cached items are saved with meaningless names and the database contains a table with the meaningless name and original URL (as well as many other columns).
So to make use of the WebView cache you'd need to access that database to find the meaningless name that contains a cache URL object.

I'm not sure if your B4A app has permission to access that database.

It looks as though you can force Android to use the device external memory for all of it's cache objects: Saving the Android WebView cache on the SD card – devahead BLOG
Note that will use the external memory for all application objects not just the WebView cache.

For Android versions greater than 2.1 it's possible in B4A to sub-class the Android Application class and override it's getCacheDir() method.

But for Android version 2.1 and earlier it would be required to override the Activity getCacheDir() method (not the Application getCacheDir() method) and that, as far as i know, is not possible in B4A.

In B4A we can sub-class the Appplication class but not the Activity class.

If you'd like to try moving the cache to external memory then let me know - it'd require a quick n simple library to be created.

Martin.
 
Upvote 0
Top