Wednesday, September 23, 2009

If-Modified-Since

When using If-Modified-Since it is important to remember that milliseconds are truncated. Many people and books say that the solution is to always truncate milliseconds before storing the time. It is NOT a good solution if the server can update entities more than once per second. Look at the example scenario below:

Client:
- getFeed Time: 12:12:12:1
Server:
- First Feed Update Time: 12:12:12:4
- Return Feed, Last Updated 12:12:12 Time: 12:12:12:14
- Second Feed Update Time: 12:12:12:56
Client:
- getFeed since 12:12:12
Server:
- Return Not Modified after 12:12:12

Server compares seconds instead of milliseconds and replies Not Modified, although there was an update after returning the feed (Second Feed Update). The solution is to store lastCheckedTime in the beginning of a request processing on the server and use it as Last Updated. Than the client would ask about changes using that time.

The other soultion is to use counters instead of timestamps.

I'll exmplain it better when I find more time:).

No comments: