Template Request: Timeline caching

Hello, My PDB simulation is at the point where I need to learn to control the timeline and cache instead of using the

bpy.ops.wm.redraw_timer(type=‘DRAW_WIN_SWAP’, iterations=1)

workaround. It would be of huge help to have a basic template of how to operate the timeline and cache already processed framed, like blenders physics system does.

perhaps a trivial example of moving an object to one side each frame.

many thanks