My current non-mountainbike stopped shifting gears on rear completely.
Rear cable frayed when I went to clean and lubricate it.
Short cable housing by rear derailleur only allows stiff cable movement.
For bikes under lighter use the gears have less changes (per year) so it can be many years before changes to gear cables and/or gear cables housing are needed but bikes under more frequent or harder use will need gear cable housing and cable changes.
I can confirm this need to replace cables/housing for bikes that I had for longer periods (unfortunately when younger my bikes could last just from 1 to 5 years before being beaten up or stolen!). My bikes have decent use a few times a week and there are hills/wind/traffic lights/etc and multiple gear shifts required every trip. Bikes have had reasonable maintenance including cable lubing and derailleur clean/lube and cable replacement. With bikes that I have had for longer times gear shifting eventually gets harder and sometimes cable snaps (snap can be near rear derailleur or at shifter) before I got to replacing.
After experiencing this now on a couple of bikes the penny has dropped. I would maintain the cables ok and replace when problems but eventually they became problematic even after new replace => HOUSING is the problem.
Anyway I'm learning here which is good.
TLDR; summary from some web grepping:
1. cables and housings wear and do need replacing before there are problems, replacement period depends on amount of use of the bike and gears.
1.1 Somewhat surprising the cable housing needs to be replaced more often than the cables.
1.2 The housing that bends right around by rear derailleur (or other bend points) can be especially a point of wear.
2. Cable might not need replacing but of course it is difficult to avoid fraying/damage.
https://www.google.com/search?q=bikes+how+long+between+gear+cable+changes
https://www.cyclechat.net/threads/when-to-change-gear-cables.245958/#:~:text=The%20outer%20cable%20where%20it,used%20on%20wet%20salty%20roads.
4 years old bike/cables well maintained, how often others change their gear cables ?
inners and outers ought to be done at the same time?
"Outers are a different kettle of fish and can need changing annually or more frequently in some instances."
"The outer cable where it curves round to the RD needs changing every 6 months if used on wet salty roads." - defo seems applicable to my situation
"The RD will be fine as the pivots last for years. Just change the jockey wheels."
"Absolutely no point changing the inners without doing the outers. The inners are just metal and can be cleaned up and lubed. The outers have a nylon type liner that gets worn, gets contaminated and loses the factory installed lubrication, the outers have by far the biggest effect on the cable/shifting performance."
https://bicycles.stackexchange.com/questions/34725/when-is-it-time-to-replace-the-gear-cable-housing
https://www.bikeforums.net/bicycle-mechanics/1240252-how-long-do-rear-derailleur-cables-last.html
"Your resulta are about on par with expectations. 3-5000 miles for a right shifter is pretty common depending on how often you shift. I've never worn a left (front) shift cable. I'd venture 10k plus but, you never know. YMMV."
"Why didn't you use a tool from your fix-it kit & drive the "H" screw all the way in to a better cog? I'm sure the 14, 15, or 16 cog would've been nicer than the 11 all the way at the bottom."
https://www.reddit.com/r/bikewrench/comments/9xaevo/roadies_how_often_do_you_change_your_housings_and/
"Housing needs to be replaced when it loses integrity (rare) or noticeably increases friction (common). The latter is either from rust at the ends or from inner liner wear at hard bends (mostly brake housing under the bar tape). Dirt, grease, and distortion at the ferrule interface can also add friction, though correcting this may not require new housing."
https://www.sheldonbrown.com/cables.html
https://sheldonbrown.com/cable-installation.html
Interesting, does not talk about housing replacement but does mention modern plastic lined cables are different, lubrication not recommended, maybe. (grease/oil breaks down plastic lining maybe). Older housings maybe did last forever if cleaned/greased/oiled.
"Cable Lubrication
In the old days, before the development of plastic-lined housing, it was necessary to coat the inner cable with light grease or heavy oil.
Modern plastic-lined cables have made the use of grease inappropriate, because the viscosity of the grease makes for sluggish cable movement. This is a more critical concern with modern brake and gear systems that use weaker return springs, and with indexed shifting in general.
Many manufacturers now recommend against using any lubrication on cables. It certainly should be avoided with sealed systems such as Gore-Tex ®. Bicycles used in wet conditions, however, will often benefit by the application of a bit of oil, more as a rust-preventive than as a lubricant. The area of particular concern is the short loop of housing which carries the rear derailer cable around from the chainstay to the derailer.
Some bicycles provide awkward cable routing which forces housing to enter cable stops/adjusting barrels at a fairly sharp angle. This is particularly common on rear cantilever brakes. It often helps to put a bit of grease on the bit of cable that runs through such fittings."