What are you planning to do with the cake once you get on the plane? If you put it in the overheard compartment, it is going to move around during the flight. Also, other passengers are not going to be careful about what they shove in the overhead compartment after the cake is in there. Your other option would be putting it under the seat in front of you, assuming it is short enough to fit. But then you have to make sure that you don't kick it. And unless you have a window seat, you have to make sure that if anybody else in your row has to scoot past you to go to the restroom, they don't kick it.
If you are a solo traveller, what are you going to do with the cake if you need to use the bathroom in the airport?