generalize cache set logic