Android + Picasso: changing URL cache expiration

后端 未结 3 1789
情书的邮戳
情书的邮戳 2020-12-03 06:20

I am using Picasso to download and display images in views all accros my application. Those images are changing very rarely (they are considered valid for a few months).

3条回答
  •  Happy的楠姐
    2020-12-03 06:48

    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);
    

提交回复
热议问题