Check if $cached is not a directory to avoid error on unlink