- af_setImage method 를 사용하면, URLCache (애플 기본 클래스) 와 AutoPurgingImageCache (Dictionary) 를 사용한다.
- URLCache 는 원본을 갖고 있고, AutoPurgingImageCache 는 filter 를 씌운 결과를 가지고 있다.
- AutoPurgingImageCache 는 cachedImages 라는 array 를 들고 있다. disk 는 사용하지 않는다.
- 필터 기능을 사용하지 않는다면 URLSessionConfiguration 에서 URLCache 를 nil로 설정해야 불필요한 두 번 저장을 피할 수 있다.
- URLCache : 20MB 메모리와 150MB 디스크 공간을 사용할 수 있다. URLSessionConfiguration 에서 조정할 수 있음.
- AutoPurgingImageCache : 100MB 메모리 공간을 사용할 수 있다. cache init 할 때 조정할 수 있음.
- memory warning notification 을 받으면 AutoPurgingImageCache 의 removeAllImages 를 호출한다.
- AutoPurgingImageCache 에 이미지를 add 했을 때, 메모리 용량을 설정값보다 많이 차지하고 있는 경우 lastAccessDate 로 정렬하여 지운다.
- URLCache 는 지워주는 부분이 따로 없기 때문에 직접 지워줘야 한다.
- expire 정책도 없다.
- 별도로 없음 (필요하다면 AutoPurgingImageCache 를 직접 만들어서 쓰도록 안내하고 있음)
- Rounded Corner, Scale, Blur 등을 제공하고 있음
let url = URL(string: "https://httpbin.org/image/png")!
let placeholderImage = UIImage(named: "placeholder")!
let filter = AspectScaledToFillSizeWithRoundedCornersFilter(
size: imageView.frame.size,
radius: 20.0
)
imageView.af_setImage(
withURL: url,
placeholderImage: placeholderImage,
filter: filter,
imageTransition: .crossDissolve(0.2)
)
- 별도로 없음 (직접 custom alamofire response serializer 를 만들도록 안내하고 있음)