Cache Fundamentals, Types, and Practical Applications in Web Development
The article surveys cache fundamentals—request flow, hit rates, eviction policies, and media—then compares local versus distributed caches and reviews concrete implementations such as programmatic caches, Ehcache, Guava, memcached, and Redis, before detailing Spring’s annotation‑driven caching and a Meituan case study on custom annotation caches.
This article, originally published in the 2017 Issue 3 of Programmer magazine and later revised, provides a comprehensive overview of caching techniques used to improve the performance and scalability of modern internet applications.
It begins by describing the typical request flow of a web or mobile application (client → network → application service → storage) and explains why limited server and database resources necessitate the introduction of caches at various stages to reduce computation and increase throughput.
The article outlines key cache characteristics such as hit rate, maximum elements (or space), and eviction policies (FIFO, LFU, LRU, and other simple strategies). It then discusses cache media, distinguishing between in‑memory, disk‑file, and database‑based caches.
Cache classifications are presented, focusing on local (in‑process) caches versus remote (distributed) caches, and the trade‑offs of each approach.
Several concrete cache implementations are examined:
Programmatic cache : simple local caches using member or static variables.
Ehcache : a popular pure‑Java cache library with support for heap, off‑heap, and disk storage, as well as optional Terracotta clustering.
Guava Cache : Google’s cache utility built on ConcurrentHashMap, offering automatic loading, size‑based eviction, and reference‑based entry handling.
memcached : a distributed in‑memory key‑value store, with details on its slab allocation, chunk management, and consistent‑hash routing.
Redis : an in‑memory data structure server that supports persistence, replication, and clustering, with explanations of its object encoding, I/O model, and eviction policies.
Practical usage patterns for Redis (e.g., leaderboards, rate limiting, pub/sub, queues) are also described.
The article then moves to cache practice, highlighting annotation‑driven caching in Spring. It explains how Spring Cache abstracts cache operations via @Cacheable, @CachePut, and @CacheEvict, and how developers can plug in custom cache managers to replace the default in‑memory implementation.
A case study of a custom annotation cache used in Meituan’s hotel‑merchant platform demonstrates domain‑level cache invalidation, conditional caching, and seamless switching between different cache back‑ends.
Finally, the author’s bio is provided: Minghui, leader of the hotel‑merchant B‑side platform at Meituan‑Dianping, with prior experience at Lenovo and Baidu.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Meituan Technology Team
Over 10,000 engineers powering China’s leading lifestyle services e‑commerce platform. Supporting hundreds of millions of consumers, millions of merchants across 2,000+ industries. This is the public channel for the tech teams behind Meituan, Dianping, Meituan Waimai, Meituan Select, and related services.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
