Fix repeated key bug, add in key cache