Fix cache race

@dkubb Good catch. I like the idea and will change it.