In this paper, we theoretically discuss the magnetocaloric effect under applied pressure and the barocaloric effect in the compounds Gd5Si2Ge2 and Tb5Si2Ge2. For this purpose, we use a model of interacting localized magnetic moments, including the magnetoelastic coupling. Our calculations show that the barocaloric quantities, upon pressure variation from 0 to 2 kbar, in the compound Gd5Si2Ge2 exhibit the normal behavior with large values, in good agreement with the available experimental data. Moreover, our theoretical calculations predict that the barocaloric quantities in the compound Tb5Si2Ge2, upon pressure variation from 0 to 6 kbar, are large as well.