如何毕加索其实缓存中的照片 [英] How Picasso Actually Cache the Images

查看:190
本文介绍了如何毕加索其实缓存中的照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道究竟毕加索库缓存应用程序中的图像。我知道它曾经HttpHeaders检查的天气,从网络获取的图像。

I would like to know how exactly Picasso Library is caching the images inside the application. I know it used HttpHeaders to check weather to fetch images from network.

不过,有它的缓存图像的任何时间框架?
像伤病退役缓存一天或某事之后?

But, is there any time frame it is caching the images ?
Like invaliding the cache after a day or something ?

现在的问题是我的项目加载来自网络的小图像数量庞大。有些时候,新的形象得到了反映在明年推出。但是,有些时候,它没有。

The problem is my project is loading huge number of small images from network. Some times, the new images got reflected in next launch. But, some times, it doesn't.

最糟糕的是,一些图像得到了体现,而其他的变化   不即使更改在同一时间进行。
但是,当我卸载应用程序,所有的图片了   反映了变化(当然。)

The worst part is, some images got reflected the changes while others are not even though the changes are made at the same time.
But, when I uninstall the App, all the images got reflected the changes (of course.)

必须有毕加索一些关于缓存。

There has to be something about caching in Picasso.

和请不要告诉我用OkHttp用于控制毕加索缓存。
我的项目是来自Apache使用AsyncHttpClient,这是太该死的大更新。
(不是我,当然,我会只是创建实现全AsyncHttpClient的小型网络辅助用的URLConnection代替。)

And please don't tell me to use OkHttp for controlling the cache in Picasso.
My project is using AsyncHttpClient from Apache and it is too damn big to update.
(not by me, of course. I would just create a small network helper with UrlConnection instead of implementing the whole AsyncHttpClient.)

总之,任何想法或指针将AP preciated。
底线:没有OkHttp。只是想了解高速缓存控制毕加索机制。

Anyway, any idea or pointer would be appreciated.
Bottom Line : No OkHttp. Just want to know about cache controlling mechanism on Picasso.

问候

推荐答案

据我所知,毕加索不清除缓存本身,因此在我们的应用程序,我们正在触发了手动。在code做到这一点是这样的:

As far as I know Picasso doesn't clear the cache by itself, therefore in our app we're triggering that "manually". The code to do it is this:

private static final String PICASSO_CACHE = "picasso-cache";

public static void clearCache(Context context) {
    final File cache = new File(
            context.getApplicationContext().getCacheDir(),
            PICASSO_CACHE);
    if (cache.exists()) {
        deleteFolder(cache);
    }
}

private static void deleteFolder(File fileOrDirectory) {
    if (fileOrDirectory.isDirectory()) {
        for (File child : fileOrDirectory.listFiles())
            deleteFolder(child);
    }
    fileOrDirectory.delete();
}

您可以触发这种清理工人每天一次/周,这取决于你需要在你的应用程序。

You can trigger this cleanup worker once a day/week, depending on what you need in your app.

这篇关于如何毕加索其实缓存中的照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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