Server: further refactor cachefile handling.

This is still not _exactly_ what I want, but we're getting closer.