I would like to build something in C# to edit the web.config of the web application.
I would like to enable the blob cache for the image renditions.
What is the best practice to edit the web.config Programmatically?
You can modify web.config settings is to use the SPWebConfigModification class of the Microsoft.SharePoint.Administration namespace, which allows you to dynamically register entities. These modifications are persisted in the configuration database where they function as a kind of virtual web.config that effectively serves as the final layer of the .config file stack for the SharePoint Foundation web application.
To enable Blob Cahce, please check this: