In Codenameone I have the following code:
String url = "http://www.example.com/advertisement.png";
String key = "goose_id-"+System.currentTimeMillis();
Dimension dimension = new Dimension(200, 200);
ImageDownloadService.createImageToStorage(url, label, key, dimension);
// Please note that every image will be assigned to
// a storage key that begins with "goose_id_" string
In this way, every time I change the file advertisement.png in the server the user, in his device, will get a different image.
My only one concern is: After several changes of the file in the server, the user is going to have ALL those images in his device. Is this correct?
I want to know if this strategy will end up running out of space the users's device.
If this is true, How can I "clean" the storage objects that begins with "goose-id-" ?
Yes, everything gets written to storage for caching.
You can prefix the cache key with a
"toDelete_"
string then use theStorage
class to loop over entries and delete them periodically. You can also do this in thestop()
method of the main class to clear the storage when the app gets suspended.