     }
 }
 
-fileprivate var localCache: [Int: [Int: URL]] = [:]
 
+private var localCache: [Int: [Int: URL]] = [:]
 extension UIImageView {
 
     func setArtwork(of artwork: Track, size width: CGFloat) {

        guard doOnMainThread(execute: self._setArtwork(id: id, generator: generator, size: width)) else {
            return
        }

        let placeholderURL = localCache[id]?.sorted(by: { $0.key > $1.key }).first?.value
        let size = { Int($0 * UIScreen.main.scale) }

        let thumbnailURL = generator(size(width / 2))
        let artworkURL = generator(size(width))

        var imageURLs = [thumbnailURL, artworkURL]
        if let url = placeholderURL, ![thumbnailURL, artworkURL].contains(url) {
            imageURLs = [url, thumbnailURL, artworkURL]
        }

        localCache[id] = localCache[id] ?? [:]
        localCache[id]![size(width / 2)] = thumbnailURL
        localCache[id]![size(width)] = artworkURL

        if let url = itm_imageURL, !imageURLs.contains(url) {
            image = nil
            setNeedsLayout()
        }
        _setImage(from: imageURLs)
    }

    private func _setImage(from urls: [URL], placeholder: UIImage? = nil) {
        guard !urls.isEmpty else { return }

        var urls = urls
        let url = urls.remove(at: 0)
        itm_imageURL = url
        pin_setImage(from: url, placeholderImage: placeholder) { [weak self] result in
            DispatchQueue.main.async {
                if url == self?.itm_imageURL {
                    self?._setImage(from: urls, placeholder: result.image)
                }
            }
        }
    }
}

    }
}

func cachedImage(with url: URL, _ completion: @escaping (Result<UIImage?, NSError>) -> Void) {
    let cache = PINRemoteImageManager.shared()
    cache.imageFromCache(withCacheKey: cache.cacheKey(for: url, processorKey: nil), options: [], completion: { r in
        if let error = r.error as? NSError {
            completion(.failure(error))
        } else {
            completion(.success(r.image))
        }
    })
}


fileprivate struct UIImageViewKey {
    static var itm_imageURL: UInt8 = 0
}
