Summarize this article:

The liner is likely to be the dirtiest part of your cap, as it soaks up sweat and skin oils while wearing. Pick an enzyme-based laundry pre-spray and spritz some on to break down this type of grime. Most modern baseball caps made in the last 10 years or so can be easily machine washed without issue. It's better to hand wash wool baseball caps. Older baseball caps tend to have cardboard brims. These caps should never be soaked completely in water. Instead, it's best to clean them with a spray bottle and washcloth. At this phase, treat your cap like any other type of laundry. Pair your cap with similarly-colored clothing and use whichever laundry detergent you prefer. Wash with cold water for the best results. However, warm water should be fine, too. Do not use hot water when washing your cap. Do not use bleach. Once the wash cycle has finished, remove your cap and place it on a flat surface in a well-ventilated area. You may choose to position an electric fan nearby to speed up the drying process. Do not put your cap in the clothes dryer; it would likely shrink or lose its shape.
Pre-treat the liner or headband. Toss your cap in with your normal laundry. Leave your cap to air dry.