Cache design-in-process cache

1. What

Cache some data in the process of the site or service, this is the in-process cache.
Can cache json data, html pages, objects.
Insert picture description here

二、Why

  1. Faster, one less network request (such as requesting redis)
  2. Save the internal network bandwidth, one less network request (such as requesting redis)

Three, How

For example, Java can implement in-process caching through a locked map. Or, you can use a third-party library, such as leveldb.
scenes to be used:

  1. Read-only data.
  2. Extremely high concurrency, if the backend pressure is extremely high, it is transparently transmitted. For example, the spike business has extremely high concurrency, requiring the site layer to block traffic, and memory caching can be used.
  3. To a certain extent, data inconsistent business is allowed. For example, in some counting scenarios, operation scenarios, pages have low requirements for data consistency, you can consider using in-process page caching.

Four, Note

Note1: In-process caching brings about the problem of data consistency (because the data is cached on multiple nodes of the site and service, the data is stored in multiple copies, and consistency is more difficult to guarantee), how to solve it, there are three solutions:

  1. Single node notifies other nodes-real-time consistency
    Insert picture description here
  2. Decoupling of MQ notification method-real-time consistency
    Insert picture description here
  3. Pull data from the backend regularly-non-real-time consistency, eventual consistency
    Each node starts a timer, pulls the latest data from the backend regularly, and updates the memory cache.
    Insert picture description here

Note2: In addition, there is an architecture design rule in the layered architecture: The site layer and the service layer must be dataless and stateless, so that nodes can be scaled arbitrarily, and the data and state are stored in the back-end data storage service as much as possible. In-process caching of sites and services actually violates the stateless principle of layered architecture design, so it is generally not recommended. In addition to the three scenarios mentioned in the third point above.

Refer

  1. https://blog.csdn.net/z50L2O08e2u4afToR9A/article/details/80809269

Guess you like

Origin blog.csdn.net/hudmhacker/article/details/108389906