As stated, modern teflon line outer cables do not require lubrication.
These cables are often designated as being 2P-class cables. 1P cables lack the liner. Not all cables carry such an indication, visual inspection will quickly show if a liner is present. A teflon liner is a thin, plastic layer inside the outer cable, often white or light blue.
If you have older, or cheaper cables, without such a liner, lubrication is required. Teflon lined cables with inner cables that have corroded and are stuck should be replaced, due to damage to the inner cable and/or liner. In an emergency however, lubrication can help to unstick these cables.
Note that WD-40 is NOT a lubricant and should never be used for any type of serious lubrication. It does more harm than good. See also this related question. Buy a specific cable lubricant, which is designed for penetrating through the whole cable. If this is not available, any other light oil or grease will do.
Cable lubrication is much easier using a specific cable lubricator. Mount the lubricator with the large hole over the outer cable, the small hole over the inner cable. Tighten the screws (gently!), insert the lubrication spray can straw and insert small quantities of lubricant until it flows out the other end. In general, you would want to lubricate from top to bottom, in order to have gravity help distribute the lube. Not for the brake cables however, be very careful not to get any lubricant on your brake pads/disc/wheel rim or any other friction part. For brakes, always lubricate Bottom-Top, or completely detach the cable from the brake before lubricating.