Pavel, I have not taken on your patch for review, but I was reading the history of it, and one question popped up:
If you are allocating a new cache, what if the array is really big, will 1st cache + your cache get bigger than work_mem? (or are array op's not constrained by work_mem? Sorry, I have not used array's so not sure if there are memory limits on them)
-Andy