Ensure format is uniform when used as cache key

Ensure that format is a symbol before using it as a cache key, this ensures
that differing formats will cause differing cache keys regardless of
string/symbol, and that similar formats will hit any existing cache.

The weird way of checking is done to reduce the possibility of DDoS through
symbol creation.

Fixes #13208 too.