[Redis] SpringBoot + Redis + Ehcache achieve secondary cache

I. Overview

1.1 Some doubts?

  • Ehcache local memory
  • Redis distributed cache can be shared

  • A (redis) and two concepts (Ehcache) when the object is linked to redis, prepared with a station (local cache JVM)

  • A (Ehcache) and secondary concept (redis) go local, go in if there is no local network, more efficient point.

  • And the difference between Redis database:

    • The same point: for a network connection is required.
    • Except that: the storage medium is stored in memory, database data above the hard disk.
    • From efficiency, the database needs to be done IO operation, performance is lower than the direct operation of memory efficiency.
  • Ehcache need to take the network to access it?

    • No, available directly from memory.
    • Ehcache will produce memory overflow: container limit, will persist on the hard disk.
    • The purpose is to reduce the pressure redis access, it can also increase the speed of access.

1.2 Scene

  • Boot Spring integrates the Spring Cache, and there are ways to achieve a variety of caching, such as: Redis, Caffeine, JCache, EhCache and so on. But if only one cache, either there will be a larger network consumption (such as Redis), or is the memory footprint is too large (such as Caffeine this application memory cache). In many scenarios, can be combined to achieve a secondary cache, it is possible to a large extent to improve the efficiency of the application process.

1.3 cache, the cache produce two

  • Simple to understand, it is to cache data read from the reading on slow media read out into the fast medium, such as disk -> Memory. We will usually store data to disk, such as: database.
  • If you read from the database each time to go, it will affect the reading speed because the IO disk itself, so there will be a redis such as memory cache.
  • Data can be read out into the memory, so when you need to get the data, we can get data directly from memory returned, the speed can be greatly improved.
  • But generally redis are individually deployed as clusters , so there will be consumed on the network IO, though links to redis clusters already have this tool connection pool, but the data transmission is also still have some consumption.
  • So there within the application cache, such as: caffeine. When qualified data buffers within the application, can be used directly, instead of through a network to acquire the redis, thus forming a second-level cache. Application of the buffer is called a cache, remote cache (e.g. Redis) is called the secondary cache

1.4 Process Analysis

Second, the project to build

SpringBoot-Redis_Ehcache

Guess you like

Origin www.cnblogs.com/haoworld/p/redisspringbootredisehcache-shi-xian-er-ji-huan-cu.html