I want to use picasso to load an image from a url into a placeholder, but not store that image in cache - in other words, I want the image to be downloaded from the net directly to disk and then loaded from disk when needed. I understand there's a class called RequestCreator where you can specify memory policy - does anyone have an example of using picasso/requestcreator to do something like this?
我想使用picasso将图像从url加载到占位符中,但不将该图像存储在缓存中 - 换句话说,我希望将图像从网络直接下载到磁盘,然后在需要时从磁盘加载。我知道有一个名为RequestCreator的类,你可以在其中指定内存策略 - 有没有人有一个使用picasso / requestcreator做这样的事情的例子?
So.. something like:
所以...类似于:
RequestCreator requestCreator = new RequestCreator();
requestCreator.memoryPolicy(MemoryPolicy.NO_CACHE);
....
merged with:
Picasso.with(context).load(someurl).fit().placeholder(someplaceholder).into(sometarget)..
3 个解决方案
#1
Picasso supports this by it's skipMemoryCache()
in the Picasso builder. An example is shown below.
Picasso通过Picasso构建器中的skipMemoryCache()来支持它。一个例子如下所示。
Picasso.with(context).load(imageUrl)
.error(R.drawable.error)
.placeholder(R.drawable.placeholder)
.skipMemoryCache()
.into(imageView);
With the new API you should use it like this so that it skips looking for it and storing it in the cache:
使用新API,您应该像这样使用它,以便它跳过查找它并将其存储在缓存中:
Picasso.with(context).load(imageUrl)
.error(R.drawable.error)
.placeholder(R.drawable.placeholder)
.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
.into(imageView);
NO_CACHE
Skips memory cache lookup when processing a request.
处理请求时跳过内存缓存查找。
NO_STORE
Skips storing the final result into memory cache. Useful for one-off requests to avoid evicting other bitmaps from the cache.
跳过将最终结果存储到内存缓存中。对于一次性请求很有用,可以避免从缓存中驱逐其他位图。
#2
For picasso:2.71828
or above version use the following for skipping using disk cache networkPolicy(NetworkPolicy.NO_CACHE)
:
对于picasso:2.71828或更高版本,使用以下内容跳过使用磁盘缓存networkPolicy(NetworkPolicy.NO_CACHE):
Picasso.get()
.load(camera_url)
.placeholder(R.drawable.loader2)
.networkPolicy(NetworkPolicy.NO_CACHE, NetworkPolicy.NO_STORE)
.into(img_cam_view);
#3
just append this at the end of url.
只需将其附加到网址的末尾即可。
"?=" + System.currentTimeMillis();
#1
Picasso supports this by it's skipMemoryCache()
in the Picasso builder. An example is shown below.
Picasso通过Picasso构建器中的skipMemoryCache()来支持它。一个例子如下所示。
Picasso.with(context).load(imageUrl)
.error(R.drawable.error)
.placeholder(R.drawable.placeholder)
.skipMemoryCache()
.into(imageView);
With the new API you should use it like this so that it skips looking for it and storing it in the cache:
使用新API,您应该像这样使用它,以便它跳过查找它并将其存储在缓存中:
Picasso.with(context).load(imageUrl)
.error(R.drawable.error)
.placeholder(R.drawable.placeholder)
.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
.into(imageView);
NO_CACHE
Skips memory cache lookup when processing a request.
处理请求时跳过内存缓存查找。
NO_STORE
Skips storing the final result into memory cache. Useful for one-off requests to avoid evicting other bitmaps from the cache.
跳过将最终结果存储到内存缓存中。对于一次性请求很有用,可以避免从缓存中驱逐其他位图。
#2
For picasso:2.71828
or above version use the following for skipping using disk cache networkPolicy(NetworkPolicy.NO_CACHE)
:
对于picasso:2.71828或更高版本,使用以下内容跳过使用磁盘缓存networkPolicy(NetworkPolicy.NO_CACHE):
Picasso.get()
.load(camera_url)
.placeholder(R.drawable.loader2)
.networkPolicy(NetworkPolicy.NO_CACHE, NetworkPolicy.NO_STORE)
.into(img_cam_view);
#3
just append this at the end of url.
只需将其附加到网址的末尾即可。
"?=" + System.currentTimeMillis();