Data caching is an important technique in wireless ad hoc networks, where it can increase data availability and significantly improve the efficiency of information access by reducing the access latency and bandwidth usage. However, designing efficient caching algorithms is non-trivial when network nodes have limited memory. After analyzing the benefit function of DGA (distributed greedy algorithm) (by Tang), an improved DGA algorithm (IDGA) is proposed and the factor of data access frequency is investigated to get better performance in this paper. The data access frequency is divided into two parts, which are local access frequency and other node access frequency, and then different weights are assigned to them respectively. Thus, data caching can be implemented based on different network application. The simulation results using the network simulator NS2 show that, compared with DGA, our algorithm is more applicable, and different benefit functions can be chosen for various applications to get lower latency and higher availability.