Casimir effect modified surface energy of a nanocavity in homogeneous media