Tuesday 26 March 2019

Caching image on disk using AlamofireImage

ImageDownloader in AlamofireImage automatically handles downloading and caching image tasks.

Example code: 


After the first run, try turn off network on your mac. If the image is displayed at the second time without network connection, it means the image is well cached on disk by default.

You can find the cached image through the following steps to:

  • Open Activity Monitor
  • Keep the app running and search for the App name
  • Double click and go to Open Files and Ports tab
  • Search for "caches" and you will find the path


/Users/{username}/Library/Developer/CoreSimulator/Devices/{device-id}/data/Containers/Data/Application/{app-id}/Library/Caches/{app-name}

If you initialised ImageDownloader as above, the cached image should sit in org.alamofire.imagedownloader/fsCachedData
 

AlamofireImage also allows to customize the cache path and capacities of on-disk/in-memory cache.


Only difference is now the image will be cached under
/Users/{username}/Library/Developer/CoreSimulator/Devices/{device-id}/data/Containers/Data/Application/{app-id}/Library/Caches/{app-name}/{diskPath}/fsCachedData

No comments:

Post a Comment