Skip to content

Commit

Permalink
Fix cache not working properly for URLs with many parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
3lvis committed Jan 5, 2017
1 parent 9cdacb2 commit 680d344
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
6 changes: 2 additions & 4 deletions Sources/Networking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,7 @@ extension Networking {
}
}
case .data, .image:
let trimmedPath = path.components(separatedBy: "?").first!

let object = self.objectFromCache(for: trimmedPath, cacheName: cacheName, responseType: responseType)
let object = self.objectFromCache(for: path, cacheName: cacheName, responseType: responseType)
if let object = object {
TestCheck.testBlock(self.disableTestingMode) {
completion(object, [String: Any](), nil)
Expand All @@ -486,7 +484,7 @@ extension Networking {

var returnedResponse: Any?
if let data = data, data.count > 0 {
guard let destinationURL = try? self.destinationURL(for: trimmedPath, cacheName: cacheName) else { fatalError("Couldn't get destination URL for path: \(path) and cacheName: \(cacheName)") }
guard let destinationURL = try? self.destinationURL(for: path, cacheName: cacheName) else { fatalError("Couldn't get destination URL for path: \(path) and cacheName: \(cacheName)") }
let _ = try? data.write(to: destinationURL, options: [.atomic])
switch responseType {
case .data:
Expand Down
3 changes: 1 addition & 2 deletions Tests/NetworkingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ class NetworkingTests: XCTestCase {
let path = "/4973/as-images.apple.com/is/image/AppleInc/aos/published/images/i/pa/ipad/pro/ipad-pro-201603-gallery3?wid=4000&amp%3Bhei=1536&amp%3Bfmt=jpeg&amp%3Bqlt=95&amp%3Bop_sharpen=0&amp%3BresMode=bicub&amp%3Bop_usm=0.5%2C0.5%2C0%2C0&amp%3BiccEmbed=0&amp%3Blayer=comp&amp%3B.v=Y7wkx0&hei=3072"

networking.downloadData(for: path) { downloadData, error in
let cacheKey = path.components(separatedBy: "?").first!
let cacheData = networking.dataFromCache(for: cacheKey)
let cacheData = networking.dataFromCache(for: path)
XCTAssert(downloadData == cacheData!)
}
}
Expand Down

0 comments on commit 680d344

Please sign in to comment.