THURSDAY, OCTOBER 18, 2012
HttpWebRequest and NotModified
If you store a request's Entity Tag, and set the IfNoneMatch on the next request, the HTTP Response Status is 304 Not Modified. The response does not include the payload (the idea being that it is already in your cache and hasn't changed). This speeds up requests and reduces bandwidth consumption because less data is transferred.
Oddly, in the .NET Framework, any status except 200 OK causes an exception to be thrown. You can catch the exception and see if the status was 304 Not Modified, and if so continue on. If the status was 404 Not Found, then you know to return null. If the status was 500+, then you know there was actually something wrong.
Everyone knows that exceptions are slow. It is pounded into our heads when we start developing.
I don't know this for sure. I cannot find any research, and I don't feel like testing it myself, but I suspect that any performance benefit gained from using Entity Tags is lost since a slow exception is thrown and must be handled.
I would have rathered that the ResponseStream be empty and the status be set. Then a simple if condition could have been used.
Posted by Chet at 2:34 PM
Post a Comment
Feel Free To Share Your Thoughts
You can use [b], [u], [i], and [url]
More About Me
Philosophy for Understanding Theology
20,000 Leagues Under the Sea
Settlers of Catan
Misc Arduino projects