Rewritten to use generic cache handling functions in cache.c.