A One-Dimensional (One-D) numerical model to calculate transient temperature distributions in a liquid-piston compressor with porous inserts is presented. The liquid-piston compressor is used for Compressed Air Energy Storage (CAES), and the inserted porous media serve the purpose of reducing temperature rise during compression. The One-D model considers heat transfer by convection in both the fluids (gas and liquid) and convective heat exchange with the solid. The Volume of Fluid (VOF) method is used in the model to deal with the moving liquid-gas interface. Solutions of the One-D model are validated against full CFD solutions of the same problem but within a two-dimensional computation domain, and against another study given in the literature. The model is used to optimize the porosity distribution, in the axial direction, of the porous insert. The objective is to minimize the compression work input for a given piston speed and a given overall pressure compression ratio. The model equations are discretized and solved by a finite difference method. The optimization method is based on sensitivity calculations in an iterative procedure. The sensitivity is the partial derivative of compression work with respect to the porosity value at each optimization node. In each optimization round, the One-D model is solved as many times as there are optimization nodes, and each time the porosity value at a single optimization node is changed by a small amount. From these calculations, the sensitivity of changing the porosity distribution to the total work input (objective) is obtained. Based on this, the porosity distribution is updated in the direction that favors the objective. Then, the optimization procedure marches to the next round and the same calculations are completed iteratively until an optimum solution is reached. The optimization shows that porous media with high porosity should be used in the lower part of the chamber and porous media with low porosity should be used in the upper part of the chamber. An optimal distribution of porosity over the chamber is obtained.