Avoid exception when entity_cache not enabled.

#5896