Device-to-Device (D2D) communication can support the operation of cellular systems by reducing the traffic in the network infrastructure. In this paper, the benefits of D2D communication are investigated in the context of a Fog-Radio Access Network (F-RAN) that leverages edge caching and fron-thaul connectivity for the purpose of content delivery. Assuming offline caching, out-of-band D2D communication, and an F-RAN with two edge nodes and two user equipments, an information-theoretically optimal caching and delivery strategy is presented that minimizes the delivery time in the high signal- to- noise ratio regime. The delivery time accounts for the latency caused by fronthaul, downlink, and D2D transmissions. The proposed optimal strategy is based on a novel scheme for an X -channel with receiver cooperation that leverages tools from real interference alignment. Insights are provided on the regimes in which D2D communication is beneficial.