Device-to-Device (D2D) communication with caching technology has emerged as a promising technique for offloading the traffic and boosting the throughput of the fifth generation (5G) cellular networks. The combined impact of cache memory size of user equipments (UEs) and content sizes, which are two crucial factors in D2D-assisted caching networks, were usually ignored in the existing researches. In this paper, an optimization algorithm is proposed to maximize the cache hit probability and cache-aided throughput, with the consideration of various cache memory sizes of UEs and content sizes. Firstly, users are grouped according to the cache memory sizes and the content sizes. Then the general mathematical expressions for the optimization of cache hit probability and cache-aided throughput with the constraints of cache memory sizes and content sizes are obtained. Subsequently, a Packet Cache Strategy (PCS) algorithm is proposed to obtain the caching probability matrix with the maximum cache hit probability and cache-aided throughout by taking user caching probability of a file as a variable. Finally, numerical results show that the sizes of the requested files affect the caching willingness of users, and the proposed PCS can achieve the highest cache hit probability and the best cache-aided throughput comparing with two other existing methods. INDEX TERMS D2D-assisted caching, cache hit probability, cache-aid throughput, file size, memory size.