     let dateDownloaded: Date
     let data: Data
     let response: URLResponse
-    
-    func isExpired(_ timeToLive: TimeInterval) -> Bool {
-        
-        return Date().timeIntervalSince(dateDownloaded) > timeToLive
-    }
 }
 
 private final class WebCache {

    private var cache = [URL: WebCacheRecord]()
    
    func cleanup(_ cleanupInterval: TimeInterval) {
        
        cache.keys.forEach { (key) in
            let cacheRecord = self[key]!
            if shouldDelete(cacheRecord, cleanupInterval) {
                cache[key] = nil
            }
        }
     }
    
    private func shouldDelete(_ cacheRecord: WebCacheRecord, _ cleanupInterval: TimeInterval) -> Bool {
        
        return Date().timeIntervalSince(cacheRecord.dateDownloaded) > cleanupInterval
    }
    
    subscript(_ url: URL) -> WebCacheRecord? {

	static let shared = DownloadWithCacheManager()
	private var cache = WebCache()
	private static let timeToLive: TimeInterval = 10 * 60 // 10 minutes
	private static let cleanupInterval: TimeInterval = 5 * 60 // clean up the cache at most every 5 minutes
	private var lastCleanupDate = Date()

	func download(_ url: URL, _ callback: @escaping OneShotDownloadCallback) {

		if lastCleanupDate.timeIntervalSinceNow < -(5 * 60) {
			lastCleanupDate = Date()
			cache.cleanup(DownloadWithCacheManager.timeToLive)
		}

		let cacheRecord: WebCacheRecord? = cache[url]
		if let cacheRecord = cacheRecord {
			callback(cacheRecord.data, cacheRecord.response, nil)
			return
		}

		OneShotDownloadManager.shared.download(url) { (data, response, error) in

			if let data = data, let response = response, response.statusIsOK, error == nil {
				let cacheRecord = WebCacheRecord(url: url, dateDownloaded: Date(), data: data, response: response)
