Fix cache decoding, optimise encoding