Use connection caching for DB based data sources.

Profiling data indicates that this is speeding up SQLite
connections, and so probably it is better this way for
MySQL as well. Redis was already doing this type of caching,
but it is now more resilient against disconnects.