How alibaba/jetcache works
Based on our analysis of the provided file tree and README, the project is a multi‐module Java caching abstraction library called JetCache. Its purpose is to offer a uniform Cache API delivering advanced caching features (such as method caching with annotations, two‐level caching, auto-refresh, distributed locks, and asynchronous operations) while abstracting over various caching implementations (in-memory caches like Caffeine or LinkedHashMapCache and remote caches such as Redis via multiple clients and even Tair).
Main Components
• Client Applications & Usage:
– This includes sample applications such as the Spring Boot samples and simple-samples which demonstrate how to interact with JetCache.
• Annotation & AOP Support:
– The “jetcache-anno” and “jetcache-anno-api” modules provide annotations (e.g., @Cached, @CacheInvalidate, @CacheUpdate, @CacheRefresh) that let developers declaratively manage caching. Also include the AOP interceptors (found under jetcache-anno/aop) that handle method interception.
• Core Cache API and Implementation:
– The “jetcache-core” module is the heart of the framework. It contains the cache abstractions (e.g., Cache interface, CacheManager), common utilities for creating and managing cache instances, and the underlying logic for operations such as key generation, serialization, and refresh policies.
• Cache Manager and Configuration:
– The CacheManager (and its related components found in the core and autoconfigure modules) is responsible for creating cache instances according to QuickConfig settings and for managing aspects like two-level caching (local + remote).
• Integration/Auto-configuration:
– The “jetcache-starter” modules (and their submodules for Redis with Jedis, Lettuce, or Redisson) provide Spring Boot auto-configuration support. They wire up the caching environment seamlessly when used in a Spring Boot application.
• External Cache Connectors and Support:
– The “jetcache-support” modules deliver integration with third-party cache backends such as Redis. Separate modules exist for different Redis connectors (lettuce, spring-data-redis, redisson).
• Testing and Documentation:
– The “jetcache-test” module contains extensive tests (both unit and integration) to validate behavior across various modules.
– Documentation (docs folder), examples (in samples), and configuration files (e.g., application.yml, docker-compose.yml) can be noted as supportive informational components.
Relationships and Interactions to Illustrate
• That client code (sample apps or Spring Boot applications) calls methods on service classes where caching is applied via annotations.
• How the CacheManager, upon reading configuration (QuickConfig and auto-configuration modules), instantiates specific Cache implementations from either the in-memory (jetcache-core embedded caches) or remote modules (e.g., jetcache-support/redis-xxx).
• Distributed mechanism: when configured for two-level caching, an update in the remote cache triggers a broadcast (or local cache invalidation) using strategies present in the code (e.g., via CacheNotifyMonitor, broadcast managers).
Architectural Patterns and Design Principles
• The design makes use of a layered architecture. At the top, client application code and declarative annotations drive behavior.
• The framework employs the Facade pattern by offering a unified Cache API that abstracts away the differences between caching engines.
• The use of AOP (aspect-oriented programming) is central for declarative caching support.
• Dependency Injection is used (especially when integrating with Spring Boot) to wire up CacheManager, auto-configuration beans, and annotation support.
• Extensibility is a key design principle – the modular structure (with distinct modules for annotations, core, starters, and support) ensures that adding new caching providers or customization points is straightforward.
Relevant Technologies and Frameworks
• Java (minimum JDK 1.8)
• Maven is used for project/module definition and dependency management.
• Spring Framework/Spring Boot for auto-configuration and integration (as highlighted in both the README and samples).
• Integration with various caching systems: Redis (via Jedis, Lettuce, Redisson), in-memory caches (Caffeine, LinkedHashMap), and (in non-open-source parts) Tair.
• Testing frameworks and build automation (CI workflows with GitHub Actions and Travis).
Final Advice
• The goal is to clearly delineate major layers: how caching is abstracted, how it is configured (via annotations and auto-configuration), and how different cache implementations are plugged in.