Fix cache related bugs