fix potential endless loop in automatic cache cleanup