1

My app creates temporary files with File.createTempFile (...) in the directory returned by getCacheDir (). Then clear the cache with the solutions given here: How-to-delete-cache-folder-of-app

Using the "Device File Explorer" tool I can see that the files are deleted, as the image shows (It is not a synchronization failure because I can see them when I do not delete them): Device File Explorer

However, the device cache indicator shows the opposite: indicator1 Next, the cache indicator when the App is newly installed: indicator2

I have tried all methods. I have also checked that there are no files in getExternalCacheDir (). I have managed to influence the device cache indicator sometime, but I have not detected the pattern. Thank you very much in advance.

Community
  • 1
  • 1
FER31
  • 76
  • 8
  • The cache size shown in your image may well include things cached by the OS, such as elements of your APK that get unpacked when the app is run. Since you are not the one coming up with that cache size, you have no way of knowing what the device manufacturer might be including in that value. – CommonsWare Jan 18 '20 at 20:56
  • Thanks for the quick reply. I can see how the cache is increasing as I create temporary files. However, when I delete the files (file.deleted ()), it is not shown in the cache indicator and keeps the same number of megabytes. – FER31 Jan 18 '20 at 21:03
  • That is up to the device manufacturer and/or Google (as developers of Android). The value might vary by device and/or OS version. How and when the value is calculated might vary by device and/or OS version. If you are deleting the files, you have done your part, and the rest is handled by other code written by other developers, and we do not control that. – CommonsWare Jan 18 '20 at 21:09
  • Thank you. That reassures me. I have noticed that the view of the device cache storage indicator is updated at each change when I create a new temporary file, so I am concerned that it is not updated when I delete. I'm afraid that my app will not be able to work if the cache runs out and I have already checked the failures it causes (with ~ 2.5 Gb of cache used). Maybe my device only lets me clear the cache a number of times per minute / hour / day or maybe it takes time to reflect the change and I am not letting it act. Thanks for the answers, it reassures me. – FER31 Jan 18 '20 at 21:18
  • I would use lower-level OS stuff, rather than that app, for measuring your consumed cache. Device File Explorer is a good choice to see what files exist and do not exist. You can also use `adb shell df` to see how much disk space is being used, at least on some devices (the `df` command may not be on all of them). – CommonsWare Jan 18 '20 at 21:25
  • I tried using du -h in the path copied from "Device File Explorer" but I get: Permission denied. The df command gives me a somewhat unlikely result, indicating only 390 MB of available global cache and I have used more at some time. – FER31 Jan 18 '20 at 22:20

1 Answers1

0

I just checked that the deletion is certainly not instantaneous. But it is finally done. Thank you very much for the attention.

FER31
  • 76
  • 8