Include response metadata + big refactor

Including converting database management code to a singleton instead of
passing it around everywhere. Also introduced a singleton cache
management class for dealing with a simple in-memory cache for avoiding
tons of database calls just to count the total number of rows in the
measurements table every time the API is hit (we really don't need this
number to be 100% up to date).

Happily, after including the response metadata (count + prev / next
links) the performance hasn't really degraded at all. Before introducing
the cache, the throughput did decrease rather significantly, but that's
hardly surprising since the performance seems to be heavily constrained
by the database accesses, so adding another query into the result
processing code was bound to have a noticable affect.