Hi Dear,
Welcome to HCM.
Understanding your concern.
Thanks for your query.Well cavities occur due to decmineralization of tooth beyond certain limit from where remineralization  can not be possible .Mostly the foods we eat and lack of 
oral hygiene will lead to cavity formation.
There can be many treatment options for 
dentist depending upon the condition of the tooth.Dentist may order X-ray before deciding the treatment option .
If the cavity is shallow then he/she may fill it with composite or silver filling after removing the infected tissue.
If cavity is deep ,but do not reach the pulp dentist may fill cavity with composite and  silver filling  after removing infected tissue ,but in this case he/she may apply liner or base before filling to prevent post filling senstivity.
If infection has already reached the pulp then 
root canal should be performed by removing the pulp and fill it with gutta percha and then give cworn on it.
If there is pain in your tooth having cavity you should apply clove oil to it , try to eat from other side and maintain oral hygiene.
Hope your concern has been resolved.
Get Well Soon.
Best Wishes,
Dr. Harry Maheshwari