毕加索何时刷新图像缓存 [英] When does Picasso refresh image cache

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

问题描述

我正在使用毕加索从服务器中获取图像.

I am using picasso to fetch images from server.

这就是我正在使用的.

            Picasso.with(getApplicationContext()).load(imageURL)
                    .placeholder(R.drawable.card_loading)
                    .fit().centerCrop()
                    .into(imageView);

上面的代码应该cache图片,但是当我在服务器上更新相同的图片而不更改其URL时,它开始在应用程序上显示新图片,而应该在cached上显示旧图片该应用程序.

The above code should cache the images, but when i update the same image on server, without changing its URL, it starts displaying the new image on app, whereas it should display the cached old image on the app.

在某些设备中,它显示的是旧图像,我关闭并重新启动了该应用多次,然后它也开始在这些设备上显示新的图像.

In some devices it was displaying the older images, i closed and restart the app multiple times, then it started displaying the new images on those devices as well.

我的问题是picasso将图像保留在缓存中多长时间,以及如何从服务器或客户端中增加图像

My Question is that how long picasso keep an image in cache, and how can i increase this from server or client

推荐答案

我不确定缓存文件的有效时间.但是您可以使用传入的HTTP响应标头更改缓存文件的有效性.基本上,您可以创建拦截器并添加带有"Cache-Control"名称的新标头.

I'm not sure how long cache file valid. But you can change cache file validity with incoming http response header. Basically you can create interceptor and add new header with "Cache-Control" name.

 OkHttpClient httpClient = new OkHttpClient();
    httpClient.networkInterceptors().add(new Interceptor(){

        @Override
        public Response intercept(Chain chain) throws IOException {
            Response originalResponse = chain.proceed(chain.request());
            return originalResponse.newBuilder().header("Cache-Control", "max-age=" + (60 * 60 * 24 * 365)).build();
        }
    });

之后,您可以将其作为http客户端传递给毕加索

After that you can pass it to picasso as a http client

这篇关于毕加索何时刷新图像缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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