  Many biological, social and man-made systems are better described in terms of
temporal networks, i.e. networks whose links are only present at certain points
in time, rather than by static ones. In particular, it has been found that
non-Markovianity is a necessary ingredient to capture the non-trivial temporal
patterns of real-world networks. However, our understanding of how memory can
affect the properties of dynamical processes taking place over temporal
networks is still very limited, being especially constrained to the case of
short-term memory. Here, by introducing a model for temporal networks in which
we can precisely control the link density and the strength and length of memory
for each link, we unveil the role played by memory on the dynamics of epidemic
spreading processes. Surprisingly, we find that the average spreading time in
our temporal networks is often non-monotonically dependent on the length of the
memory, and that the optimal value of the memory length which maximizes the
spreading time depends on the strength of the memory and on the density of
links in the network. Through analytical arguments we then explore the effect
that changing the number and length of network paths connecting any two nodes
has on the value of optimal memory.
