Use content type cache when type casting.

Thansk to @rbas for the suggestion.