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

前端 未结 2 1632
被撕碎了的回忆
被撕碎了的回忆 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:30

    This example use OkHttp as http client for Picasso and setup max Disk cache size and also memory cache.

     // Size in bytes (10 MB)
     private static final long PICASSO_DISK_CACHE_SIZE = 1024 * 1024 * 10;
    
     // Use OkHttp as downloader
     Downloader downloader = new OkHttpDownloader(getApplicationContext(),
                            PICASSO_DISK_CACHE_SIZE);
    
      // Create memory cache
      Cache memoryCache = new LruCache(maxSize);
    
      mPicasso = new Picasso.Builder(getApplicationContext())
                            .downloader(downloader).memoryCache(memoryCache).build();
    

提交回复
热议问题