A memoizer for complicated postgres queries