I tell everyone -- don't drink the Kool-Aid. Never believe that a company has any loyalty and always keep an eye on the market. Even if you are paid well now and see that your job isn't gaining you marketable skills -- leave. At the end of the day, as a person in technology, your major resources are your technical skills.
I will leave a company in a heartbeat if I see that the company's technical direction isn't in line with what the market wants. I'm in my 40s and biggest fear is being unemployable -- not being unemployed.
I haven't had to do it yet, but hopefully, I would have the discipline to leave a job where I'm overpaid with respect to the market to take a job that pays a little less that keeps me competitive.