Use relative paths in DB and Cache

We use the absolute URI to load the book contents, but when we store the
metadata for the book, we only store the relative location. The reason
is, if we decide to change the store location (either move to a
different store, or use a local store for debugging), we don't want to
keep fixing the metadata each time, and we don't want it to be stale.

Also used this opportunity to do a bunch of bug fixes and refactoring.