To consider only the cassette is the wrong way to think about it. Cassettes and chains wear together.
As the chain wears*, so the teeth of the cassette gears wear to match. So a really old chain and cassette will continue to work a lot better than a new chain on an old cassette, or an old chain on a new cassette.
It depends of course on how many mile the bike has been ridden. A chain and cassette that has been ridden 50miles in 2 years will be 'newer' than one that have been ridden 1000miles in 6 months.
There's a tool you can get that measures chain wear. Slip that into your chain and see how if fits. Depending which tong of the tool fits cleanly into the chain, that defines what needs replacing. I've found that less than 0.5 and your fine for a little while longer. 0.5-0.75 and you should replace the chain. If you've left it too long, and it's over 0.75 you should definately the chain and probably replace the cassette (depending on how flush you are). If it's over 1.0, then you should definately replace both.
Ultimately, first try replacing just the chain. If it works ok, the chain engages with the cassette well, you get no gears skipping, and changes don't hesitate (while riding); then you're good to go. If the teeth don't mesh, the chain skips over teeth, and you get chain slip (under load); then you'll need to change the cassette too.
I change chain every 6 months, cassette every year, and chainrings every 2 years. Has worked well enough for me.
* contrary to popular belief... chains don't actually stretch (more than a minute amount). They wear. The roller cylinders in the chain wear agains the teeth of the gears, increasing the distance between interfaceing surfaces.