Three caching scheme

Cache to solve the problem

  • Improve performance
    in most cases, select the largest local performance problems. On the one hand, select something like this there will be many rich semantic join, group, order, like, and these are very time consuming semantic properties; on the other hand, most applications are reading and writing less so exacerbated the slow query problem.
    Distributed systems remote call will consume a lot of performance, because of network overhead, will lead to an overall decrease response time. In order to save this performance overhead, in the case of (not too real-time data) service allows the use of cache is very necessary thing.
  • Database relieve the pressure
    when the user requests increases, the database will greatly increase the pressure, can greatly reduce the pressure on the database by caching.

Cache application scenarios

  • For less demanding real-time data
  • For some frequently accessed but rarely change the data, read much more than write for the cache is very necessary. Some sites such as configuration items.
  • For high performance requirements, such as some of the spike activity scenes.

Cache three modes

  • Cache Aside update mode (while updating the cache and database)
  • Read / Write Through update mode (to update the cache, the cache is responsible for synchronizing update the database)
  • Write Behind Caching update mode (to update the cache, the cache update timing of asynchronous database)

Cache Aside update mode

This is the most commonly used cache mode.

Process

Here Insert Picture Description

Read / Write Through mode update

Process

Here Insert Picture Description

Write Behind Caching update mode

Process

Here Insert Picture Description

to sum up

Three kinds of cache mode advantages and disadvantages:

  • Cache Aside update mode relatively simple to implement, but need to maintain two data storage, is a cache (Cache), a database (Repository).
  • Read / Write Through update mode only need to maintain a data store (cache), but more complicated to implement.
  • Write Behind Caching update mode and the Read / Write Through similar update mode, the difference update data Write Behind Caching persistent mode operation is asynchronous, but the data Read / Write Through updating persistent mode operation is synchronous. It features high speed direct memory operation, multiple operations may be combined persisted to the database. The disadvantage is that data may be lost, such as a system power failure.
  • Caching is used to improve performance at the expense of strong consistency. So use caching to improve performance, there is a delay in updating the data. This requires us to think carefully about whether or not suitable for caching combined business at design time. Then be sure to set the cache expiration time, this is not a good time is too short too long, too short, then the request will be more likely to fall on the database, it also means losing the advantage of the cache. Too long, then the cache of dirty data make the system a long time in a delay of state, and the system for a long time people did not access data stored in memory has not expired, wasting memory.
He published 196 original articles · won praise 6 · views 20000 +

Guess you like

Origin blog.csdn.net/fall_hat/article/details/104671355