Java geek


Related reading:

JAVA basics (1) Simple and thorough understanding of inner classes and static inner classes (2) Memory optimization – Caching using JAVA references (3) JAVA basics (3) ClassLoader implementation hot loading JAVA Foundation (4) Enumeration (enum) and constant definition, factory class use contrast (5) JAVA Foundation (5) Functional interface reuse, decouple the edge of JAVA programming ideas (1) Extensibility through dependency Injection (2) JAVA Programming ideas for interfaces (3) Remove the ugly if, Self-registration strategy mode elegantly meets the open and close principle JAVA programming thought (4) Builder mode classic paradigm and factory mode how to choose? HikariPool source code (two) design ideas for reference in the workplace (a) IT factory survival rules


1. Project address

warehouse address
github Github.com/alibaba/jet…
Yards cloud Gitee.com/mirrors/Jet…

2. Engineering structure

JetCache’s engineering structure is as follows:

The son of engineering describe
jetcache-anno Spring-based support for @cached and @createcache annotations.
jetcache-anno-api Define annotations and constants for JetCache without passing dependencies. If you want to add Cached annotations to your interface and don’t want your interface JAR to pass too many dependencies, you can make the jar rely on jetcache-anno-API.
jetcache-core Core API, fully programmed to configure operation Cache, independent of Spring. Two in-memory cache implementations of LinkedHashMapCache and CaffeineCache are also provided by it.
jetcache-starter Enable to be used in Spring
jetcache-support Adaptation to different scenarios using Redis.
jetcache-test The test code
samples Using the example

3. Level-0 conceptual model

Any business system, after the understanding of its core business concept, the follow-up can quickly do more in-depth understanding and extension on this basis, to achieve twice the result with half the effort. The following is the core concept of JetCache, which corresponds to the class or interface in the code:

  • Cache




  • Cleaner




  • CacheBuilder
  • There is no uniform use of cache factories for creation, which is more decoupled because each cache is created in a different way and independent creators do not affect each other.

  • CacheEvent




  • CacheResult




  • CacheValueHolder




  • CacheConfig




  • RefreshPolicy




  • KeyConvertor




  • CacheLoader




  • CacheMonitor




  • CacheStat




  • 4. Write your own caching tool

    Developer capability level:

    level Have the ability to
    primary Coding can be done according to detailed design documents.
    The intermediate The coding can be done according to the conceptual model. (There will be some clarification, of course).
    senior Have independent modeling ability, own modeling and coding.

    It is recommended that intermediate developers try to write their own caching tools based on the above core concepts, and see how well they can write. It doesn’t matter if they are good or bad, but if the questions you encounter during the writing process make you think and try to find the answers, it will greatly improve your coding ability.

    You don’t have to write it well, just use the concepts, and the data structure for the cache is ConcurrentHashMap.

    4. To summarize

    1 read the source code can be coarse to fine, first roughly look at the directory/engineering structure, core concepts, and then layer by layer, can get twice the result with half the effort.

    2. Debugging is the most effective way to speed up the understanding of the source code, after a general understanding of the code, quickly debugging up.

    3. Pay more attention to gradually improve my ability to model and complete coding independently.

    end.


    <– Read the mark, left like!