Clean up API views / improve caching

Huge refactor of views_api.py. Could be abstracted further but not worth the effort for now.