Is cache condition necessary to stop HTML being inserted into database cache?
No, there is a better way to do this. Set the enableTemplateCaching config value to false.

'enableTemplateCaching' =&gt; false,


With that setting disabled, all caching will be skipped.

// Won't be cached
{% cache for 1 hour %}