使用CodenameOne优化客户端存储中的空间 [英] Optimizing the space in the client's storage with CodenameOne

查看:78
本文介绍了使用CodenameOne优化客户端存储中的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Codenameone中,我有以下代码:

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

$开头的存储键b
$ b

这样,每次我在服务器中更改文件advert.png时,用户

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.

如果这是真的,我如何清理以 goose-id-开头的存储对象?

If this is true, How can I "clean" the storage objects that begins with "goose-id-" ?

推荐答案

是的,所有内容都会写入存储以进行缓存。

Yes, everything gets written to storage for caching.

您可以在缓存键前添加 toDelete _ 字符串,然后使用 Storage 类可循环遍历条目并定期删除它们。您也可以在主类的 stop()方法中执行此操作,以在应用程序暂停时清除存储空间。

You can prefix the cache key with a "toDelete_" string then use the Storage class to loop over entries and delete them periodically. You can also do this in the stop() method of the main class to clear the storage when the app gets suspended.

这篇关于使用CodenameOne优化客户端存储中的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆