Is it possible to change the size of the cache Picasso uses for images?

前端 未结 2 1633
被撕碎了的回忆
被撕碎了的回忆 2021-01-03 16:09

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 cache

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-03 16:37

    You can do:

    int maxSize = MAX_CACHE_SIZE;
    Picasso picasso = new Picasso.Builder(context)
                                  .memoryCache(new LruCache(maxSize))
                                  .build();
    

    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.

    Seems like the other answer uses the wrong function. It should be memoryCache, not setCache.

提交回复
热议问题