Skip to content

Commit

Permalink
Remove Request.isDefaultProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Oct 3, 2016
1 parent 6870440 commit c57ade2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
19 changes: 2 additions & 17 deletions Sources/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,9 @@ public struct Request {
/// Processor to be applied to the image. `Decompressor` by default.
public var processor: AnyProcessor? {
get { return container.processor }
set {
applyMutation {
$0.processor = newValue
isDefaultProcessor = false
}
}
set { applyMutation { $0.processor = newValue } }
}

var isDefaultProcessor = true // false when processor is changed from the outside

/// The policy to use when dealing with memory cache.
public struct MemoryCacheOptions {
/// `true` by default.
Expand Down Expand Up @@ -155,15 +148,7 @@ public extension Request {
/// `URLRequests` and the same processors. `URLRequests` are compared
/// just by their `URLs`.
public static func cacheKey(for request: Request) -> AnyHashable {
// User provided custom key
if let key = request.cacheKey { return key }

// We can avoid creating a separate Request.Key and just pass an absolute
if request.isDefaultProcessor, let str = request.container.urlString {
return AnyHashable(str)
}

return AnyHashable(Key(request: request) {
return request.cacheKey ?? AnyHashable(Key(request: request) {
$0.container.urlString == $1.container.urlString && $0.processor == $1.processor
})
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/RequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ class RequestCacheKeyTests: XCTestCase {
XCTAssertTrue(Request.cacheKey(for: request1) == Request.cacheKey(for: request2))
}

func testThatRequestsWithDefaultURLRequestAndURLAreEquivalent() {
let request1 = Request(url: defaultURL)
let request2 = Request(urlRequest: URLRequest(url: defaultURL))
XCTAssertTrue(Request.cacheKey(for: request1) == Request.cacheKey(for: request2))
}

func testThatRequestsWithDifferentURLsAreNotEquivalent() {
let request1 = Request(url: URL(string: "http://test.com/1.png")!)
let request2 = Request(url: URL(string: "http://test.com/2.png")!)
Expand Down

0 comments on commit c57ade2

Please sign in to comment.