Newer magnets are made of materials that are far less likely to lose their magnetism over time than the old horseshoe magnets.
Magnets are composed of many little magnetic regions called domains.
The magnetic field of the whole magnet runs opposite to the direction of the domains that cause the field.
That tends to make the domains reverse their magnetism.
In modern magnets, the domains are energetically stuck, more or less, making them less vulnerable to this effect.
Such a magnet will lose its magnetism only if it is heated to a high temperature or subjected to vibrations.
The new magnets use materials like alnico, an aluminumnickel-cobalt compound, and cobalt samarium that have internal structures that prevent the deterioration of the magnetic circuit.
They are divided into many little particles, each of which is one domain.
In contrast, the old horseshoe magnets had domains that were much bigger, solid pieces of iron, with the domains bounded by little impurities made of iron carbide.
Paradoxical as it may seem, small particles of an optimum size are more energetically stable than large ones in magnetic substances, a discovery made only in the last few decades.