Fix cache key collision and add test for cache key distinctness.