'Cavalry' - certainly in the British Commonwealth forces were for the most part mounted infantry that fought on foot - the horse still then being the fastest way in which an infantry man could move cross country.
They did not as a rule 'charge' at the enemy (there are some classic examples where they did - but those are generally exceptions that prove the rule) but used their mobility to move to a position at which point the men would dismount with every 4th man taking the horses to 'the rear' and the unit would fight as infantry in the way that Mechanized units would deploy their infantry to fight on foot and the APCs to not generally fight the enemy directly.
The disadvantage was that Cavalry units tended to be smaller in number than their equivalent Infantry units (400-500 odd compared to 600-800 odd in an Infantry battalion) and this was further reduced as every 4th man would not actually fight but take charge of his and 3 other men's horses after they had dismounted - reducing the effective number of fighting men in a given company/platoon further by 25% effectively less than half an infantry Battalion.
Obviously the advantage that they allowed was that they could exploit a situation (or address a situation) 3x faster than an infantry unit and be less fatigued when they got their with the intention being that they would be relieved by the slower moving Infantry.
As for being obsolete in the face of modern arms - be it magazine bolt action rifles, reliable belt fed machine guns, artillery (Shrapnel and HE) and barbed wire....well that's true buts its also true of Infantry.
Where a Cavalry unit could not survive in such an environment - pretty much neither could infantry and both resorted to manning trenches.
So where the need to have to move a large body of armed infantrymen cross country as fast as possible exists 'Cavalry' will exist - and before reliable vehicles exist - which is arguably the late 30s at the earliest - 'Cavalry' or horse mounted infantry will stay relevant.
Most of the text above perfectly describes the Australian Light Horse Regiments, in Palestine in WW1.
The "Charge" at Beersheba, is a classic example of the effect of rapid movement, as the Australians came in so fast the Turkish troops didn't have time to adjust their sights, so most of their fire was going way over. Two things possibly led to this - the attack came out of a supposedly impassable desert, and fell on a "rear area" so the quality of the defending force may have been a bit down, leading to panic, and forgetting to adjust, as the range closed.
Even as late as 1941 Australia still maintained mounted units, mainly militia, in home defence, which were promptly converted to armour, or infantry, once the Japanese became a threat.
However, right through WW11, the long isolated, uninhabited coastlines of northern Australia were patrolled by "Curtain's Cowboys", (named after John Curtain, the Prime Minister of the time,) mounted units, living off the land.