Implement model caching

Add unit tests