After my previous post I remembered the UE 4 course notes to also mention a specular parameter which was later replaced by cavity. I'm having a hard time understand what cavity is used for as it seems similar to roughness.
my guess is that it's a final multiplier, like the spec color in your original code -- white = no change, black = all spec lighting is removed.
In a physically based shader, even if you set f0/spec-mask to 0%, if you view the material at a glancing angle, 1-100% of the light will still be reflected due to Fresnel.
When you have little cavities, lake gaps between plates of armor, this looks weird. In reality, the shadow system should take care of this, but on a low-poly model, that cavity may not even exist (so it can't be shadowed). So, it's like doing a very fina AO bake on your model, or letting you artist hand paint areas where they want to remove the specular reflections.
Picking up your example, lets say we have a highly reflective/metallic material that's been polished. In my case that might be metallic 1 and roughness 0. Now I want to have some small details with less highlights. I could say the roughness is higher here, or the cavity is higher. What is the difference?
If the roughness is 0, you'll only see a reflection if H•N is exactly 1 (or in other words if R•L is exactly 1). Increasing the roughness relaxes this, so H•N can be smaller and smaller (less aligned) but a highlight is still produced. Yes, as roughness increases, the intensity of the highlight also decreases, because it's being spread over a large area (assuming were conserving energy).
Tweaking the cavity on the other hand just reduces the intensity directly, without affecting the size/shape of the highlight.