Rewrite generate cache code to fix method

only two instances of each task max