Skip to content Skip to sidebar Skip to footer

Setting Key For Picasso For S3 Amazon

I am trying to use amazon S3 Client for my files uploading and downloading. For caching i am trying to use Picasso right now. There are few points to note. 1- In S3, there is no si

Solution 1:

What you probably want is to keep cache of the generated urls in say a HashMap, and if there is no value for a certain key, then generate the url with getAmazonTempUrl() and store it in the cache.

If you set the URL expiry time to an hour then you can record the activity load time into a variable, and check if that has been longer than an hour. If so, clear the cache.

What you can also do is do a callback with Picasso in case the image fails and recreate the url:

Picasso.with(this).load(imageUrl).into(imgaeView, new Callback() {
                @Override
                public void onSuccess() {

                }

                @Override
                public void onError() {
                    //recreate the url here and store in cache
                }
            }
    );

Edit:

So in your case you could persist the above cache and load it next time the app is started. To deal with image changing under the same url you can try do it the dirty way or the clean way.

The clean way is to change the url for the image if you can. If that's not an option - you can perhaps check the image's last modified date and append that as a timestamp on the url. e.g http://www.sample.com/image.jpg?14869246263 - this works fine with Picasso's cache as long as the the url is exactly the same.

The dirty way is to load the cached version and then immediately after force-reload the same image around the cache (used to be done with skipCache() I believe, but was deprecated in favour of somethingCachePolicy).

Post a Comment for "Setting Key For Picasso For S3 Amazon"