是否可以更改毕加索用于图像的缓存大小? [英] Is it possible to change the size of the cache Picasso uses for images?
问题描述
我正在使用Picasso从URL(http://)加载图像.
有时,当我尝试使用Picasso的fetch()
方法预加载"图像时,该图像不会被缓存.我猜是因为它太大了.
I'm loading images from URLs (http://) with Picasso.
Sometimes when i try to "preload" an image using Picasso's fetch()
method, the image doesn't get cached. I guess it's because it's size is too big.
阅读这个问题的答案,但setCache()
似乎没有为我所认可,我什至没有在毕加索文档中找到它.
Read the answer for this question, but setCache()
doesn't seem to be recognized for me, i don't even find it in the Picasso documentation.
有什么方法可以更改毕加索用于位图的缓存大小吗?
Is there any way to change the cache size Picasso uses for bitmaps?
推荐答案
您可以这样做:
int maxSize = MAX_CACHE_SIZE;
Picasso picasso = new Picasso.Builder(context)
.memoryCache(new LruCache(maxSize))
.build();
Picasso
使用 Cache
接口类型来管理缓存.它们提供了默认实现 LruCache
,具有构造函数,该结构接受最大大小(以字节为单位)作为参数.
Picasso
uses a Cache
interface type to manage the cache. They provide the default implementation, LruCache
, which has a constructor that accepts the max size in bytes as an argument.
似乎其他答案使用了错误的功能.应该是memoryCache
,而不是setCache
.
Seems like the other answer uses the wrong function. It should be memoryCache
, not setCache
.
这篇关于是否可以更改毕加索用于图像的缓存大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!