move purge dir cache functionality to it's own method