permutation with cached