Add some cache tests and fix bugs they found.