It really depend on the brand and model. In general, you should expect around 10 years from a reliable brand like LiftMaster. Unfortunately, cheaper opener brands often use cheap capacitors and other internal components to cut costs, and their lifespan may be much shorter.
If you are experienced with soldering, it is possible to purchase the same capacitor for a few bucks and replace them by yourself. But it’s very important to follow all the safety guidelines as electric openers contain very powerful capacitors that can be very dangerous if handled incorrectly!