user2990765
user2990765

Reputation: 387

Why does URLSessionTaskMetrics have an array of transactionMetrics

It appears that URLSessionTaskMetrics contains an array of transactionMetrics and as per Apple's documentation, the transactionMetrics contains "An array of metrics for each individual request-response transaction made during the execution of the task". My question is how does a URLSessionTask have multiple requests? When we create a session task we create it with a single request object, so how is it possible for a single session task to contain an array of metrics? Shouldn't it be only one?

Upvotes: 0

Views: 559

Answers (1)

Zev003
Zev003

Reputation: 91

there are two cases, I can get.

  1. the status code of response is 302.
  2. session task will request two times cause of the default value of request.cachePolicy is useProtocolCachePolicy. the first one fetches data from the local cache and the second fetch data from the net. However, if request.cachePolicy is reloadIgnoringLocalCacheData, its count will less 1.

try print transactionMetrics and compare the difference between them.

Upvotes: 0

Related Questions