We consider a p2p network delivering content among mobile users. Users are requesting items, and at the same time carrying a local cache which may be used to store items and hence serve the request of another user, when these are connected through a local wireless link. In this opportunistic system, we analyze how to allocate optimally content to caches when users exhibit heterogeneous content popularity and mobility, as well as impatience. These factors are shown to greatly impact the efficiency of the cache allocation as content requesters follows different delay utility functions, however, we show that this allocation problem satisfies a general convexity property. Moreover, since no global state of the caches can be maintained in such opportunistic environment, we present a simple algorithm using a series of dynamic content elections and proves that, as the number of users becomes large, the results of these elections maximize the system's social welfare. To the best of our knowledge this is the first distributed algorithm which can handle users heterogeneity and is rigourously proved to converge to an optimal caching policy.