Optimal cache replacement