设置毕加索键亚马逊S3 [英] Setting key for picasso for S3 Amazon

查看:233
本文介绍了设置毕加索键亚马逊S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Amazon S3的客户端我的文件上传和下载。对于缓存我试图用毕加索现在。

I am trying to use amazon S3 Client for my files uploading and downloading. For caching i am trying to use Picasso right now.

有几点需要注意。
1-在S3中,没有单一的链路为一个文件。我有随机生成每个图像的URL。此URL将在1分钟之后到期最有可能还是可以将其设置为在1小时内到期。

There are few points to note. 1- In S3, there is no single link for a file. I have to randomly generate a url for each image. This url will expire most likely in 1 min or i can set it to expire in 1 hour.

在我的我的适配器我打电话像这样的onCreateView

In my onCreateView of my adapter i am calling something like this

String url = getAmazonTempUrl()

2 - 每个文件的名称将是相同的,但他们可以在服务器上进行修改。例如abc.png是一个文件的名字,我可以今天和明天1MB有可能是多了一个形象出现。

2- Each file name will be same but they can be modified on server. e.g abc.png is a file name and i can be 1mb today and tomorrow there could be one more image there.

现在我要问怎样才能毕加索办理这样的场景的关键。网址是改变所有的时间在一个单一的卷轴。另外的名字是一样的。我不想毕加索检查名称,不下载新的更新的文件。

Now i want to ask how can picasso handle the key for such scenario. The url is changing all the time IN A Single scroll. Also name is same. I do not want picasso to check name and don't download new updated file.

推荐答案

你可能想要的是保持生成的URL的高速缓存中说的是HashMap,如果有一定键的值,然后生成的URL getAmazonTempUrl(),并将其存储在缓存中。

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.

如果你的URL过期时间为一个小时,那么你可以记录活动加载时间到一个变量,并检查是否已经超过一个小时。如果是这样,清除缓存。

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

编辑:

所以你的情况,你可以坚持上述缓存和下一个应用程序启动时加载它。为了处理相同的URL下的图像变化,你可以尝试做的肮脏的方式或清洁的方式。

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.

清洁方法是,如果你可以改变的URL的形象。如果这不是一种选择 - 你或许可以查看图像的最后修改日期,并追加了作为URL中的时间戳。如 http://www.sample.com/image.jpg?14869246263 - 这工作细跟毕加索的缓存只要网址是完全一样的。

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.

肮脏的方式是加载缓存的版本,然后后立即强制重新加载缓存大约在同一图像(用于与skipCache()我相信做,但赞成somethingCachePolicy的pcated德$ P $)。

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

这篇关于设置毕加索键亚马逊S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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