Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDURLCache.m line 189 issue #44

Open
steveriggins opened this issue Oct 27, 2013 · 2 comments
Open

SDURLCache.m line 189 issue #44

steveriggins opened this issue Oct 27, 2013 · 2 comments

Comments

@steveriggins
Copy link

Forgive me for my lack of cache knowledge. I was code reviewing SDURLCache.m the other day and was puzzled by line 189 in the "Expires" logic block. In this method, the code calculates "now" based on the Date in the response (or now if none) If a cached response header has a date of yesterday morning, and an expires of this morning, this method appears to calculate an interval of 24 hours, and then returns an expiration date based on 24 hours from now

Am I reading that entirely incorrectly? Or is it some case where if there is an Expires header, there won't be a Date header?

Thanks!

@rs
Copy link
Owner

rs commented Oct 28, 2013

This complies to the HTTP spec. To prevent from clock skewing, HTTP client must not use their own clock to compute expiration but server's by using the Date response header. If a server doesn't provide a Date response header, response should be considered as uncacheable.

By the way, SDURLCache is no longer necessary as iOS 5+ implemented disk cacking.

@steveriggins
Copy link
Author

Agreed, but you still need some code if you want to do cache introspection. "HTTP client must not use their own clock to compute expiration but server's by using the Date response header" I agree, but isn't the code in question doing what you said it should not?

// Date is read from cached response as yesterday at 8am

  NSTimeInterval expirationInterval = 0;
    NSDate *expirationDate = [NSURLCache dateFromHttpDateString:expires];

// expires is today at 8am
if (expirationDate)
{
expirationInterval = [expirationDate timeIntervalSinceDate:date];
}

// time interval is 24 hours
if (expirationInterval > 0)
{
// Convert remote expiration date to local expiration date
return [NSDate dateWithTimeIntervalSinceNow:expirationInterval];

// Return now + 24 hours, calculated using client's clock
}
else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants