[libsocialcache] Make thread management an internal detail of databases.

Hide most of the details of threading, database initialization and
locking away in AbstractSocialCacheDatabase and instead offer some
simple read and write virtuals within which the work can be done.

Simultaneously change from a model of dynamically generating queries for
each write to simply using static queries that are prepared once and
kept in a cache for re-use in subsequent writes.

Combined these changes reduce the total number threads used by
internally utilizing a thread pool, and cut down on time spent compiling
sql queries.