  The fifth generation wireless networks must provide fast and reliable
connectivity while coping with the ongoing traffic growth. It is of paramount
importance that the required resources, such as energy and bandwidth, do not
scale with traffic. While the aggregate network traffic is growing at an
unprecedented rate, users tend to request the same popular contents at
different time instants. Therefore, caching the most popular contents at the
network edge is a promising solution to reduce the traffic and the energy
consumption over the backhaul links. In this paper, two scenarios are
considered, where caching is performed either at a small base station, or
directly at the user terminals, which communicate using \ac{D2D}
communications. In both scenarios, joint design of the transmission and caching
policies is studied when the user demands are known in advance. This joint
design offers two different caching gains, namely, the \textit{pre-downloading}
and \textit{local caching gains}. It is shown that the finite cache capacity
limits the attainable gains, and creates an inherent tradeoff between the two
types of gains. In this context, a continuous time optimization problem is
formulated to determine the optimal transmission and caching policies that
minimize a generic cost function, such as energy, bandwidth, or throughput. The
jointly optimal solution is obtained by demonstrating that caching files at a
constant rate is optimal, which allows to reformulate the problem as a
finite-dimensional convex program. The numerical results show that the proposed
joint transmission and caching policy dramatically reduces the total cost,
which is particularised to the total energy consumption at the \ac{MBS}, as
well as to the total economical cost for the service provider, when users
demand economical incentives for delivering content to other users over the D2D
links.
