How to create a material that acts like a greenscreen...when the camera cant see but will block objects behind from being seen

Hello im looking to create a material when applied to static mesh the camera cant see but the static mesh will still block the camera from seeing meshes with a different shader when in the foreground…for example I have a cylinder with no caps/ends and with small cubes inside…when the camera is facing the side of cylinder it cant see anything…when the camera rotates to one end of the cylinder then you will start to see inside the cylinder

Thanks for the help in advance!

eager to get help, please let me know if you have questions