Java geek


Related reading:

JAVA Basic (1) simple, thorough understanding of inner classes and static inner classes JAVA Basic (2) memory optimization – Using JAVA references to do caching JAVA Basic (3) The implementation of hot loading ClassLoader (4) The use of enumerations (enum) and constant definitions. (5) The use of factory classes. (5) The use of functional interfaces – Reuse, decouple The edge of JAVA programming. The self-registration strategy pattern satisfies the open and closed principle gracefully. HikariPool source code (two) design ideas for reference in the workplace (a) IT factory survival rules


1. 为什么是JetCache

  1. It integrates Caffeine and Redis, two of the more well-known open source caching tools
  2. The documents are more detailed and updated frequently
  3. Ali open source cache tool, and Ali internal also in use
  4. The code is less complex and easier to read
  5. There are test cases for easy debugging

2. Look at the source code with the cache knowledge

As a caching tool, JetCache should have the ability of caching tools, and at the same time, it should be able to solve the common problems of caching, with the cache related knowledge to see the source of JetCache, and compare the knowledge, so the harvest is greater. The core knowledge of caching is as follows:

2.1. Cache Application Scenarios

The application scenarios of caching are as follows:

  • Reduce database I/O usage



  • Reduce CPU usage
  • 2.2. Cache classification

    2.2.1. Scope classification

    The scope of the cache can be divided into:

  • Thread level cache
  • The thread-level cache contains data in Java that corresponds to a ThreadLocal store.

  • Process-level cache
  • The process-level cache, as in JAVA, stores data corresponding to static variables.

  • Distributed cache
  • 2.2.2. Java Cache classification

    Caches in Java fall into three categories:

  • Strong reference cache



  • Soft reference cache



  • Weak reference cache
  • For a host with memory constraints, you can set the cache that is not frequently accessed to a soft or weak reference cache and automatically reclaim memory when needed.

    2.3. Cache design

    Cache design considerations include:

  • Failure of strategy



  • serialization



  • The cache monitor



  • Multistage cache
  • 2.4. Common Problems

    When using or developing a caching tool, consider whether common caching issues can be addressed, including:

  • The cache to penetrate



  • Cache avalanche



  • Cache breakdown



  • Cache pollution
  • 2.4. Open source frameworks

    There are many open source frameworks for caching. When time and energy are limited, focus on a few mainstream ones first, and then go to the others when you have time or need to go to caching experts. Now you can familiarize yourself with the following:

  • JetCache



  • Caffeine



  • Redis
  • end.


    <– read left mark, left point like!