Added in memory queue cache

Added additional exceptions
Improved database connection code