Update: If you use a recent version of Magento there might be a better solution here.
If you have been using Magento with a BIG database of products you will soon realize that the built-in “cache management” is quite limited due to the server’s usual time limit on requests. You just can’t refresh your catalog rewrites on 5000 products in less then a good 5 minutes and the other functions might give you the same problems as well.
By extracting the code from the cache management controller I was able to build a custom script that can be called via command line on the server and that will allow you to do a full cache refresh without any kind of time limit or connection timeout issues. The only requirement is shell access to your website files by SSH, Telnet or a terminal of some sort.