There are some decoders designed to accept "keep alive" capacitors. In most cases, the capacitor prevents the decoder from resetting itself when there is a momentary power interruption. The decoder must have a way to tap into the circuits behind the bridge rectifier input.
I believe the Lenz Gold decoder has an option for a "keep alive" capacitor to help keep the motor turning as well. Capacitors to power both motor and decoder for even a second or two are not small, and must be wired to the decoder correctly.
Note that a big keep alive capacitor may experience some of the same inrush current problems as QSI and other sound decoders, where the inrush current is big enough to trip the DCC system circuit breaker. And the inrush currents are additive - each inrush current adds to the total load when the DCC system is turned on or reset.
Before DCC, flywheels were the accepted way of providing stored energy to get past a momentary power interruption. Flywheels also have the benefit of resisting changes in motor speed, causing smoother running, especially during starting, stopping, and at slow speeds. And they add weight to the locomotive, which is good for traction. If the flywheel(s) is big enough, the model locomotive can actually coast a few inches when the power is shut off. Note that a flywheel does nothing to prevent a decoder reset during loss of power. It may help the engine coast past the dirty spot on the track to where it receives power again.