Fix for cache stuff

WARNING: This increases max_allowed_packet up to 1GB, you can change it
to something lower as it wont need that big sql query.
Fixed Node startup (cache generation)
Fixed some database functions that weren't closing the reader when
finished.