Monday, September 26, 2005

Server side: ETag VS Cache-Control max-age=xxxx or Expiration VS Validation

I will not cover here the whole topic of the web caching, but there things, which I'd
like to mention. They are the two caching mechanism:
1) is configured in the server ( in IIS we can set expiration date or expiration timeout ( e.g. max-age ) and on Apache we even can set cache policy for different content types )
2) no configuration in the server ( client uses "ETags" for cache validation ) - the default one.

Now lets consider 1st way, we configure web-server and set expire time as 1 hour ( max-age = 3600 ). What will now happen? Client will download the resource with the header - Cache-Control: max-age = 3600, store this value and will also store the date, when that resource was downloaded. Then every time during 1 hour when client browser
receives reference to the resource he will check download date & max-age value of it, and if the content is up-to-date, browser will not send request to the server, and it will use cached resource.

On the other hand ( 2nd way ) server has no configuration settings. Every resource downloaded from the server has it own "ETag". Next time, when browser accesses the resource it sends request to the server, and server sends response, containing error - 304 ( not modified ). This code signals client to use cached version of the resource.

While analyzing these two techniques we can come to the conclusion:
1) when using 1st way - we reduce the number of server roundtrips, thus have better network performance.
2) when using 2nd way - we have greater number of roundtrips to check the resource ETag.

The pros and cons are the following here:
1st way, greater network performance but cache will be invalidated only after period of time 2nd way, lower network performance but cache will be invalidated correctly, when resource will be changed.

The above said in the HTTP spec it is stated as
"The former reduces the number of network round-trips required for many operations; we use an “expiration” mechanism for this purpose (see section 13.2). The latter reduces network bandwidth requirements; we use a “validation” mechanism for this purpose (see section 13.3)."

From the HTTP spec:
"Caching would be useless if it did not significantly improve performance. The goal of caching in HTTP/1.1 is to eliminate the need to send requests in many cases, and to eliminate the need to send full responses in many other cases."

Update: actually 1-st and 2-nd methods can also be used togther. Using them combined can reduce not only the number of requests but also response size.
For instance if two methods are used together: the resource will at first expire and after that it will be checked (validated) for change.

Wednesday, September 21, 2005

neural networks

In the place where I study, we started new course - Neural Networks. The teacher gives us only mathematical basis, however, there is huge load of materials on the Net, with the applicable samples and source code...