我有一个应用程序,显示来自互联网的图片(展示设计师的工作).我开始在内部缓存目录中缓存我的内容,但应用程序内容可能需要大约150 MB的缓存大小.什么是Android文档说的:
您应该始终自己维护缓存文件并保持合理的空间限制,例如1MB.当用户卸载您的应用程序时,将删除这些文件.
所以我看了一下Currents应用程序(Galaxy Nexus),应用程序的缓存大小是110 MB.但奇怪的是,Google Currents和Google Maps等应用程序将内容缓存在所谓的(USB存储数据)中:

那么前一个应用程序使用的"USB存储数据"是什么呢?如果你在应用程序中实现缓存,你是否循环缓存中的所有应用程序文件,以便在每次需要插入内容时获取大小,然后进行比较和清除?或者你是否继续缓存内容,直到Android决定清理一些应用程序缓存目录的时间?
我真的很想知道在Android中管理缓存的流程是什么,或者至少其他应用程序如何处理缓存的大内容.
我需要找到一种方法如何清除我的应用程序存储在缓存中的数据.基本上我使用Fedor(在ListView中的图像的延迟加载)惰性列表实现,我想在我加载例如100个图像时自动清除缓存.任何想法怎么做?
编辑: 代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list=(ListView)findViewById(R.id.list);
adapter=new LazyAdapter(this, mStrings);
list.setAdapter(adapter);
deleteCache(this);
adapter.notifyDataSetChanged();
}
public static void deleteCache(Context context) {
try {
File dir = context.getCacheDir();
if (dir != null && dir.isDirectory()) {
deleteDir(dir);
}
} catch (Exception e) {}
}
public static boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new …Run Code Online (Sandbox Code Playgroud)