Goals: More efficient cache flush for a given path

Now all the affected objects are retrieved before handling them. This avoids
retrieving the objects, for example the directories, several times thus
querying the database several times for the same object.