add max failed time and fix some cache logic