We consider the caching of content in the mobile devices in a wireless network using maximum distance separable (MDS) codes. We focus on a small cell, served by a base station (BS), where mobile devices arrive and depart according to a Poisson birth-death process. Users requesting a particular file download coded symbols from caching devices using device-to- device (D2D) communication. If additional symbols are required to decode the file, these are downloaded from the BS. We optimize the MDS codes to minimize the downlink rate and the D2D com- munication rate under an average overall cache size constraint. We show that, for most practical scenarios, using optimized MDS codes results in significantly lower communication rate compared to when caching the complete most popular files. We furthermore show that caching coded symbols of each file on all mobile devices, i.e., maximal spreading, is optimal.