Reputation: 16191
I am saving MapTiles to my internal cache which I retrieve using getCacheDir()
. I have a few questions regarding the handling of the cache size.
Upvotes: 0
Views: 253
Reputation: 1499
Regarding 1) In my applications I often use disc based image caches. I have always used a fixed cache size, which has worked fine so far. I don't know about your size requirements, but you could determine the total available disc size and calculate some ratio of that (see: Getting all the total and available space on Android). You probably want to set some max upper limit though, users won't be happy if your app eats up all their free disc space ;)
Regarding 2) Android won't secretly delete your persisted files. The only thing that might happen is that the user decides to delete application data or all cached files of your app. In such a case, all data will be gone, and you will have to re-initialize your cache.
Upvotes: 0
Reputation: 39836
for how to handle the size, I guess the best approach is to check how much are you using:
StatFs
can also tell you what is the total sizeno, there's really nothing you can do about it. Your software should be able to check for deleted tiles and re-download them if necessary.
and as an alternative to your apprach, I suggest you to use a LruDiskCache from JakeWharton (https://github.com/JakeWharton/DiskLruCache)
I believe that re-inventing the wheel is bad and unnecessary, so if there's a library that is already doing all of most of the heavy lift, why will I bother code it again?
Upvotes: 1