General formulation of a peturbation theory for unsteady cavity flows