Move cache-uri before image-url retrieval.

NOTE: This is only in preparation for adding caching. It still needs to
actually be hooked up.
Add caching.