Android + Picasso: changing URL cache expiration

梦想的初衷 提交于 2019-11-27 13:46:32

Disk caching happens "below" Picasso inside the HTTP client. In fact, this process is completely transparent. We never explicitly ask for a cached-version or an internet-version, the HTTP client will make the decision internally and do the right thing.

Because we opted to leverage the HTTP client for caching, we're offered very little control over how the caching actually happens. To answer your question, no, there is no way to tell Picasso (or OkHttp) to cache an image for longer than its headers allow.

I solved it with a Home-made cache, the trick is to add a parameter to the URL that is not used, but making each URL different every X minutes

Calendar cal2 = Calendar.getInstance();
long d = cal2.getTimeInMillis();
int extra =  (int) Math.ceil(d/ (10*60*1000));    // 10 minutes cache

Picasso.with(getBaseContext())
            .load("http://www.myurl.cat/myimage.png&extra=" + extra)
            .placeholder(R.drawable.graphicLoading)
            .error(R.drawable.graphicLoadingError)
            .into(bottomGraphic);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!