2016-12-30 58 views
0

SDWebImage 라이브러리를 사용하여 컬렉션보기에서 이미지를로드하고 있습니다.SDWebImage 캐싱이 uicollectionview 셀의 캐시에서 이미지를로드하는 데 시간이 걸립니다.

라이브러리는 서버와 캐시에서 이미지를 다운로드하지만 내 앱을 종료하고 다시 실행하면 캐시에서 이미지를로드하는 데 시간이 걸립니다. SDWebImage를 사용하여 이미지를로드

코드 (자리 표시 자 이미지는 더욱 때로는 2 ~ 3 초 동안 표시됩니다) : 사용 여기

cell.imgPost.sd_setImage(with: URL(string: (post.lowQualityImgUrl) ?? ""), placeholderImage: UIImage(named:"greybg") , options: .refreshCached, progress: { (recievedSize, expectedSize) in 

     progressIndicatorView.progress = CGFloat(recievedSize)/CGFloat(expectedSize) 

     }, completed: { (image, error, cachetype, url) in 

      if image != nil{ 
       DispatchQueue.main.async { 
        progresView.removeFromSuperview() 
        progressIndicatorView.removeFromSuperview() 
        cell.progressIndicatorView?.isHidden = true 
        cell.imgPost.image = image 

       } 
      } 
    }) 

캐싱 옵션이 새로 고침 캐시입니다.

질문 : 컬렉션보기 셀이 sdwebimage를 사용하여 즉시 이미지를로드 할 수없는 이유를 모르겠습니다. 그것은 sdwebimage가 이미지 캐싱을위한 최상의 라이브러리라고 말한 것처럼. 누군가 해결책/문제를 지적 할 수 있습니까?

편집 저는 도서관에 의견을 남겼습니다. 결코 좋은 도서관이라고 생각하지 않습니다. https://github.com/rs/SDWebImage/issues/138

미리 감사드립니다. refreshCached

* Even if the image is cached, respect the HTTP response cache control, and refresh the image from remote location if needed. 
* The disk caching will be handled by NSURLCache instead of SDWebImage leading to slight performance degradation. 
* This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics. 
* If a cached image is refreshed, the completion block is called once with the cached image and again with the final image. 
* 
* Use this flag only if you can't make your URLs static with embedded cache busting parameter. 

당신은 당신이 동일한 URL에서 다른 이미지를 얻을하지 않는 이미지를 캐시하지 않으려면 refreshCached를 사용하지 말아야 대한 SDWebImage 문서에서

+0

왜 블록 안에 'cell.imgPost.image = image'를 사용하여 이미지를 다시 설정하고 있습니까? 그것은 이미'cell.imgPost.sd_setImage (with :'블록. – Poles

+0

에 의해 설정되고 있습니다. 만약 cell.imgpost.image = image를 두지 않으면 @Poles 다음에 이미지보기를 스크롤하면 자리 표시 자도 다시 나타납니다. 무엇이 있는지 모르겠습니다. 나는 놓친다 – user3804063

답변

0

. 기본 설정으로두면 모든 것을 처리하게됩니다.

편집 : 그냥 options을 빈 배열 []로 둡니다. 기본 설정으로 계속 진행해야합니다. 귀하의 코드에 여전히 refreshedCache이 (가) 있기 때문에 지연이 예상됩니다.

cell.imgPost.sd_setImage(with: NSURL() as URL!, placeholderImage: UIImage(), options: [], progress: { (_, _) in 

}, completed: { (_, _, _, _) in 

}) 
+0

문제는 이미지가 적절히 캐시되어 있다는 것입니다 . 하지만 캐시에서로드하는 데 시간이 걸립니다. (2-3 초) 지연 왜 이렇게 많은 시간이 걸릴까요? – user3804063