Refactor cache key generation.