It depends on what cancer and when. Ovarian cancer or prostate cancer. Prostate cancer before the age of 60 and aggressive. If every man lived to 100 they would probably have prostate cancer. If you are worried about hereditary cancer you can evaluated to have the BRCA test. BRCA is rare.
3cm cysts are on the small side. Cysts are very common and most resolve on their own within 3 menstrual cycles / months. You don't want to have surgery unless it is necessary.
When you say that your family has a history of cancer, is there a history of ovarian cancer? If so, then you could have inherited a gene for it (BRCA1 or 2 or Lynch Syndrome) but you would need to be tested to see if you have it. The only other cancer that has a link to ovarian cancer is colon cancer in those who have the Lynch Syndrome gene mutation.
If you do not have a family history of ovarian cancer, then your chances of getting it during your lifetime are extremely low (less than 2%).
Hopefully, these cysts will go away and you won't need to worry any more.