I have tried the following script to re-bake a soft-body modifier on a lattice object:
o = bpy.data.objects['Lattice']
bpy.context.view_layer.objects.active = o
o.select_set(True)
with bpy.context.temp_override(active_object=o):
bpy.ops.ptcache.free_bake()
bpy.ops.ptcache.bake_all(bake=True)
but get a context error on the free_bake() statement. It appears to work for the bake_all() statement (I use the UI to delete the bake and comment out the free_bake().
Is there a more direct way to access an object.modifier...ptcache ?
(yes: i realize some of the above code statements are probably superfluous).
PS - I observe that almost all answers involving overrides are from deprecated versions of bpy, where override is an operator arg and override is a dictionary instead of keywords (with no examples of the keywords in the python documentation!).