Fix memoize decorator for 0.16(same fix as in #6685)

Instead of cherry-picking all the commits from #6685, which also pulls unrelated code, we just fix the decorator and don't move it like in salt's develop.