Fix database connection issues in prefork mode.

When running in prefork mode, open DB connection got shared between the
child process as DB was accessed very early in the init process. One
child would then close the connection and cause others to fail. To fix
this, connection.close() was added to the end of startup procedures.
Close cache after startup procedures

Same as with DB connection, the cache connection gets shared between child
processes in prefork mode if it isn't closed after startup procedures
Merge pull request #215 from keto/fix-prefork-mode

Fix prefork mode