Fix segfault when reading cache

When erasing elements in the vector, the iterator is reset to the
wrong element.
Merge pull request #45 from jspricke/master

Fix for segfault