improve cache detection code