I have inverter and when power fails it takes around 2 sec to switch over to battery,
You need a proper UPS which will have high speed switching circuits that will detect the drop in AC power almost instantaneously and switch to backup before the AC has fully decayed. An inverter on its own isn't going to do it especially if it is being switched with a mechanical relay.
The only times capacitors are used in AC circuits is to smooth out AC ripple and in noise filters. It certainly isn't going to store any energy for longer than the length of one cycle which at 50/60 Hz is not very long.