Where does NSURLSession store ETag information?

This question is purely for understanding NSURLSession's design approach to http caching.


I can see that an ETag is present in the Cache.db with grep under AppData,


find . -type f | xargs grep "4503e35064056ad99bae1c3519e5482d"


However, looking at the database itself, I can find neither a table schema information that has ETag or the actual ETag when doing a select on the available tables.

Accepted Reply

For that purpose, is there a way to reuse whatever information is stored in the cache or expected to implement that independently?

You can probe the cache using various NSURLCache APIs (like

-cachedResponseForRequest:
). These give you back an NSCachedURLResponse, which includes both headers and body.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

IIRC it doesn’t specifically extract the ETag but instead stores it along with all the other HTTP headers. The cache is quite capable of caching resources that don’t have an ETag.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thank you! The column name through me off. Thought it was only storing the response body. Depending on whether NSURLSession implements "freshness" based on "Last-Modified" (doesn't look like it from the docs, have asked in a separate question, to be approved) I was keen on implementing it. For that purpose, is there a way to reuse whatever information is stored in the cache or expected to implement that independently?

For that purpose, is there a way to reuse whatever information is stored in the cache or expected to implement that independently?

You can probe the cache using various NSURLCache APIs (like

-cachedResponseForRequest:
). These give you back an NSCachedURLResponse, which includes both headers and body.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"