Refactor cacheCommandCase and update for D8

Still one fail to go and I'm out of energy.