Squid: WARNING! Your cache is running out of filedescriptors 2

Sometimes squid stops working and "WARNING! Your cache is running out of filedescriptors" is logged in cache.log. Restart usually resolves that problem. Temporarily though. This article is based on http://www.cyberciti.biz/faq/squid-proxy-server-running-out-filedescriptors/ adding some Gentoo specific bits. Squid, as a web cache should, holds a lot of files from internet on a local hard disk. It means that a lot of files are open at the same time. On busy servers this amount grows till the limit imposed by the operating system. Then no more files can be opened and squid seemingly dies.