Make path handling more robust

Following the recent couple of issues related to generation of the paths used in the decaching PHP I wanted to take another look at the path handling and make it a bit more robust and (I hope) easier to read too (the double / single quotes stuff wasn't the easiest on the eyes).

I think it makes much more sense to leverage the node `path` module - probably should have been written that way to begin with.