# alibaba/jetcache architecture

> Architecture diagram of the GitHub repository alibaba/jetcache, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alibaba/jetcache
- Repository: https://github.com/alibaba/jetcache

## Overview

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.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client Applications
    subgraph "Client Applications"
        client1["Simple Samples App"]:::client
        client2["Spring Boot Sample App"]:::client
    end

    %% Annotation & AOP Support
    subgraph "Annotations & AOP"
        annoApi["jetcache-anno-api: Caching Annotations"]:::annotation
        anno["jetcache-anno: AOP Interceptors"]:::annotation
    end

    %% Core Cache API & Implementation
    subgraph "Core Cache API & Implementation"
        core["jetcache-core: Cache API & Implementation"]:::core
    end

    %% Cache Manager & Configuration
    subgraph "Cache Manager & Configuration"
        cacheManager["CacheManager (from jetcache-core)"]:::config
        autoConfig["Auto-Config (QuickConfig)"]:::config
    end

    %% Integration / Auto-Configuration
    subgraph "Integration / Auto-Configuration"
        starter["jetcache-starter: Auto-configuration"]:::integration
        redisStarter["jetcache-starter-redis"]:::integration
        lettuceStarter["jetcache-starter-redis-lettuce"]:::integration
        redissonStarter["jetcache-starter-redisson"]:::integration
    end

    %% External Cache Connectors and Support
    subgraph "External Cache Connectors"
        support["jetcache-support"]:::support
        redisLettuce["Redis Lettuce Connector"]:::support
        redisSpring["Redis Spring Data Connector"]:::support
        redisOther["Redis Connector"]:::support
        redisRedisson["Redis Redisson Connector"]:::support
    end

    %% Testing and Documentation
    subgraph "Testing & Documentation"
        test["jetcache-test: Testing Modules"]:::testing
        docs["Docs: Documentation & Examples"]:::testing
    end

    %% Connections
    client1 -->|"usesAnnotation"| annoApi
    client2 -->|"usesAnnotation"| annoApi

    annoApi -->|"triggersAOP"| anno
    anno -->|"interceptsMethodCalls"| core

    core -->|"invokesCacheOps"| cacheManager
    autoConfig -->|"configures"| cacheManager

    starter -->|"wiresConfig"| autoConfig
    starter -->|"integratesRedis"| redisStarter
    starter -->|"integratesLettuce"| lettuceStarter
    starter -->|"integratesRedisson"| redissonStarter

    cacheManager -->|"usesRemoteCache"| support
    support -->|"providesConnector"| redisLettuce
    support -->|"providesConnector"| redisSpring
    support -->|"providesConnector"| redisOther
    support -->|"providesConnector"| redisRedisson

    %% Click Events
    click client1 "https://github.com/alibaba/jetcache/tree/master/samples/simple-samples"
    click client2 "https://github.com/alibaba/jetcache/tree/master/samples/spring-boot-sample"
    click annoApi "https://github.com/alibaba/jetcache/tree/master/jetcache-anno-api"
    click anno "https://github.com/alibaba/jetcache/tree/master/jetcache-anno/src/main/java/com/alicp/jetcache/anno/aop"
    click core "https://github.com/alibaba/jetcache/tree/master/jetcache-core"
    click cacheManager "https://github.com/alibaba/jetcache/tree/master/jetcache-core"
    click autoConfig "https://github.com/alibaba/jetcache/tree/master/jetcache-starter/jetcache-autoconfigure"
    click starter "https://github.com/alibaba/jetcache/tree/master/jetcache-starter"
    click redisStarter "https://github.com/alibaba/jetcache/tree/master/jetcache-starter/jetcache-starter-redis"
    click lettuceStarter "https://github.com/alibaba/jetcache/tree/master/jetcache-starter/jetcache-starter-redis-lettuce"
    click redissonStarter "https://github.com/alibaba/jetcache/tree/master/jetcache-starter/jetcache-starter-redisson"
    click support "https://github.com/alibaba/jetcache/tree/master/jetcache-support"
    click redisLettuce "https://github.com/alibaba/jetcache/tree/master/jetcache-support/jetcache-redis-lettuce"
    click redisSpring "https://github.com/alibaba/jetcache/tree/master/jetcache-support/jetcache-redis-springdata"
    click redisOther "https://github.com/alibaba/jetcache/tree/master/jetcache-support/jetcache-redis"
    click redisRedisson "https://github.com/alibaba/jetcache/tree/master/jetcache-support/jetcache-redisson"
    click test "https://github.com/alibaba/jetcache/tree/master/jetcache-test"
    click docs "https://github.com/alibaba/jetcache/tree/master/docs"

    %% Styles
    classDef client fill:#f9c,stroke:#333,stroke-width:2px;
    classDef annotation fill:#bbf,stroke:#333,stroke-width:2px;
    classDef core fill:#bfb,stroke:#333,stroke-width:2px;
    classDef config fill:#ff9,stroke:#333,stroke-width:2px;
    classDef integration fill:#fdb,stroke:#333,stroke-width:2px;
    classDef support fill:#dfd,stroke:#333,stroke-width:2px;
    classDef testing fill:#ffd,stroke:#333,stroke-width:2px;
```
