Content is not always about medias and files, computing tasks output are also a content that can be described, stored and cached. In this paper, we investigated the problem of edge computing and caching in the fog computing networks. In our scenario, we consider the user requests computing tasks from the fog, that the devices could not handle. Moreover, fogs use their storage and computing capabilities to cache the tasks computation results in order to minimize the latency, and use it storage to offload their resources by caching the significant computing tasks output. We propose a clustering method based on the correlation between the tasks and the cached content to decide what fog will give a better service in term of latency to offer better quality of service and experience. The problem of the users-fogs association was formulated as a coalition game between the users and the fogs. Finally, we use the BoltzmannGibbs learning algorithm to make every entity able to learn the best coalition, in order to enhance the convergence of the system to reach a better and optimal stability.