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