In this paper, we studied a data caching problem in edge-based CDNs to facilitate the content delivery to serve a sequence of requests, off-line and online, with minimum costs as a goal based on a semi-homo cost model. To this end, we first designed an O(mn \log(mn)) time and space optimal proactive off-line algorithm,called pro-caching, by reducing the problem to a simple shortest path problem in a directed weighted network graph, and then extended the idea of anticipatory caching to develop an 2-competitive reactive online algorithm, called re-caching, for this problem and showed its tightness by proving that no deterministic online algorithm can do better than 2-o(1) in its worst case. Finally, to combine the advantages of both algorithms, we also presented a hybrid algorithm, called hy-caching, to fully utilize the power and benefits of edge-based CDNs while reducing their service costs. Our results improve the previous results not only in the cost model being used but also in the time complexity, competitive ratio, and the quality of the solutions. We provably achieve these results with our deep insights into the problem and the careful analysis, together with an empirical evaluation.