Yes, this is safe. This will not remove anything you need. And, yes: this works the same way on most HTC phones running Marshmallow including One M9.
I would NOT do this too often myself, as it would just lead to things being reloaded (that’s how a cache works). So, if you are having serious issues with apps: this is one of the things you do/try.
Settings > Storage & USB > Phone storage > Cached data, press “Ok” to clear cache data.
What is cache?
Simplified: A cache is simply a place for temporary storage of data, meant to speed up access to that data.