What exactly is the caching technology that carries high concurrency?

2022.10.20

What exactly is the caching technology that carries high concurrency?


Cache refers to the memory that can perform high-speed data exchange. It exchanges data with the CPU before the memory, so the speed is very fast. So what is the operating logic of the cache, and what are the solutions for the cache, will be the focus of this article.

Author | Jin Peng, unit: China Mobile Smart Home Operation Center

​Labs Guide

Cache refers to the memory that can perform high-speed data exchange. It exchanges data with the CPU before the memory, so the speed is very fast. So what is the operating logic of the cache, and what are the solutions for the cache, will be the focus of this article.

Cache is a technology that stores target data in a high-speed operating layer with high accessibility. It is designed to quickly read data with high usage and infrequently updated data, avoiding repeated access to the source data layer for requests before access, resulting in additional I/O resource consumption, thereby improving business concurrency. In order to improve the running rate of data access, the cache data also needs to weigh the resource capacity, the data refresh frequency, set the expiration time, or set a reasonable cache elimination strategy. Mainstream caching solutions include CDN caching, browser caching, local caching, and external caching.

Part 01 CDN cache 

CDN refers to the content distribution network, which caches resources on CDN nodes, relies on edge servers deployed in various places, and uses the load balancing, content distribution, scheduling and other functional modules of the central platform to enable users to go to the nearest CDN cache nodes to obtain content. Reduce network latency and increase access speed. The business scenarios that use this caching technology include: HTML, CSS, JS and other static files in front-end projects, downloading firmware packages in the Internet of Things, resource requests in remote multi-active architectures, and so on. Deploying or caching these files on CDN nodes improves resource access speed while ensuring resource access stability.

Part 02 Browser cache 

Browser caching means that when the browser communicates with the back-end server through the request-response mode under the HTTP protocol, after the first request is sent to the server and the result is obtained, the cache will be implemented according to the caching rules in the response message. For example, under the HTTP/1.1 protocol, mandatory caching rules will be implemented according to Cache-Control; under mandatory cache invalidation, the caching rules will be determined according to the cache ID in the request. Browser session persistence is also a cache implementation. At present, the mainstream technical solutions include Cookie mechanism, Session mechanism, and Token mechanism.

picture

Part 03 Local cache 

Local caching refers to caching the response data in the server's application process memory space to reduce the I/O consumption of the query persistence layer. The advantage is that the data does not need to be transmitted across the network, the reading performance is better, and the supported QPS is higher; Locally cached data will be lost. Caffeine, a local caching solution implemented in the Andlink cloud platform project, has the following dependencies:

<dependency>
    <groupId>com.github.ben-manes.caffeine</groupId>
    <artifactId>caffeine</artifactId>
    <version>${caffeine.version}</version>
</dependency>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

Part 04 External cache or distributed cache

Corresponding to the local cache is the external cache or distributed cache, which is deployed independently of the application process and can be designed in a cluster mode to ensure data read and write separation, high performance, and high availability. The distributed cache implemented in the Andlink cloud platform project is a solution based on the Spring Boot Cache framework to integrate Redis clusters. This solution can well solve common business pain points such as data loss, business concurrency, fault recovery, and dynamic storage expansion. Combined with business requirements, Redis provides comprehensive solutions, such as stand-alone mode, master-slave mode, cluster mode or sentinel mode. The sentinel mode can realize health detection and automatic recovery, and is the preferred mode to ensure the stable operation of high-concurrency services. The dependencies of the scheme are as follows:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
    <version>${redis.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-cache</artifactId>
    <version>${cache.version}</version>
</dependency>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.

Of course, there are many mainstream caching technology solutions, but the general direction is to reduce the underlying performance overhead and improve the high concurrency capability of the business. At present, the Andlink cloud platform supports hundreds of millions of users and tens of millions of device requests, and caching technology plays an important role in it.