Cavity induced perfect absorption in metamaterials