Improvements to initialisation time for large services with couchdb caches

With init_db called during init our large services (600+ layers) were taking a very long time to init and saturating the available connectons back to couchdb.

1) Only initialise the DB when a connection is required, not once for every cache at service initialisation.

2) Lock to prevent initialising more connections than required (e.g. when multi simultaneous connections are received).