# symfony/cache architecture

> Architecture diagram of the GitHub repository symfony/cache, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/symfony/cache
- Repository: https://github.com/symfony/cache

## Overview

##### Main Component Structure

- TagAwareAdapter interface branch

b. Adapter Layer (Arrange in a circular pattern around the core):
Adapters into categories:
- In-Memory Adapters (ArrayAdapter, NullAdapter)
- File-based Adapters (FilesystemAdapter, PhpFilesAdapter)
- Database Adapters (PdoAdapter, DoctrineDbalAdapter)
- Distributed Cache Adapters (RedisAdapter, MemcachedAdapter, CouchbaseAdapter)
- Special Purpose Adapters (ChainAdapter, ProxyAdapter, TraceableAdapter)

##### Integration Components (Top Layer)
- PSR-16 Bridge (Psr16Cache)
- Messenger Integration
- DataCollector for Symfony Profiler integration

##### Support Components (Bottom Layer)
- Marshaller System (DefaultMarshaller, DeflateMarshaller, SodiumMarshaller)
- Exception Hierarchy
- DependencyInjection Integration

Use the following visual elements:

- Blue: Core components
- Green: Adapters
- Orange: Integration points
- Purple: Support services

##### Connections
- Double lines: Interface realization

##### Important Details
- PSR-6 compliance relationship
- Tag-aware functionality flow
- Early expiration handling through Messenger
- Marshaller transformation process

##### Layering
Create distinct layers showing:
##### Integration Layer

Key Relationships to Emphasize:
- How adapters extend AbstractAdapter
- Tag-aware adapter inheritance chain
- Marshaller interaction with adapters
- Early expiration message flow
- DependencyInjection compilation passes

- Any abbreviations or special symbols

Keep the abstraction level appropriate by:
- Focusing on the component interaction rather than implementation details
- Showing major data flows
- Highlighting extension points
- Emphasizing the adapter pattern implementation

Remember to add notes about:
- The role of DependencyInjection in configuring adapters
- How the marshaller system serializes cache items
- The tag-aware caching mechanism
- Integration with Symfony's profiler through the DataCollector

This will provide a complete picture of how the caching system works while maintaining clarity and usefulness for development decisions.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core
        CacheItem["CacheItem"]:::core
        AbstractAdapter["AbstractAdapter"]:::core
        TagAwareInterface["TagAwareAdapterInterface"]:::core
    end

    subgraph "In-Memory Adapters"
        ArrayAdapter["ArrayAdapter"]:::adapter
        NullAdapter["NullAdapter"]:::adapter
    end

    subgraph "File-based Adapters"
        FilesystemAdapter["FilesystemAdapter"]:::adapter
        PhpFilesAdapter["PhpFilesAdapter"]:::adapter
    end

    subgraph "Database Adapters"
        PdoAdapter["PdoAdapter"]:::adapter
        DoctrineDbalAdapter["DoctrineDbalAdapter"]:::adapter
    end

    subgraph "Distributed Cache Adapters"
        RedisAdapter["RedisAdapter"]:::adapter
        MemcachedAdapter["MemcachedAdapter"]:::adapter
        CouchbaseAdapter["CouchbaseBucketAdapter"]:::adapter
    end

    subgraph "Special Purpose Adapters"
        ChainAdapter["ChainAdapter"]:::adapter
        ProxyAdapter["ProxyAdapter"]:::adapter
        TraceableAdapter["TraceableAdapter"]:::adapter
    end

    subgraph "Integration Layer"
        Psr16Bridge["Psr16Cache"]:::integration
        MessengerIntegration["Messenger Integration"]:::integration
        DataCollector["CacheDataCollector"]:::integration
    end

    subgraph "Support Layer"
        DefaultMarshaller["DefaultMarshaller"]:::support
        DeflateMarshaller["DeflateMarshaller"]:::support
        SodiumMarshaller["SodiumMarshaller"]:::support
        DependencyInjection["DependencyInjection"]:::support
        ExceptionHandler["Exception Handler"]:::support
    end

    subgraph "Early Expiration"
        EarlyDispatcher["EarlyExpirationDispatcher"]:::expiration
        EarlyHandler["EarlyExpirationHandler"]:::expiration
        EarlyMessage["EarlyExpirationMessage"]:::expiration
    end

    subgraph "Tag-Aware System"
        AbstractTagAware["AbstractTagAwareAdapter"]:::tagaware
        TagAwareAdapter["TagAwareAdapter"]:::tagaware
        TagAwareMarshaller["TagAwareMarshaller"]:::tagaware
    end

    %% Core Relationships
    AbstractAdapter --> CacheItem
    TagAwareInterface --> AbstractAdapter

    %% Adapter Relationships
    ArrayAdapter & NullAdapter & FilesystemAdapter & PhpFilesAdapter & PdoAdapter & DoctrineDbalAdapter & RedisAdapter & MemcachedAdapter & CouchbaseAdapter & ChainAdapter & ProxyAdapter & TraceableAdapter --> AbstractAdapter

    %% Tag-Aware Relationships
    AbstractTagAware --> AbstractAdapter
    TagAwareAdapter --> AbstractTagAware
    TagAwareMarshaller --> DefaultMarshaller

    %% Integration Relationships
    Psr16Bridge --> AbstractAdapter
    MessengerIntegration --> EarlyDispatcher
    DataCollector --> TraceableAdapter

    %% Early Expiration Flow
    EarlyDispatcher --> EarlyMessage
    EarlyMessage --> EarlyHandler

    %% Support Relationships
    DefaultMarshaller & DeflateMarshaller & SodiumMarshaller --> AbstractAdapter
    DependencyInjection --> AbstractAdapter

    %% Click Events
    click CacheItem "https://github.com/symfony/cache/blob/7.2/CacheItem.php"
    click AbstractAdapter "https://github.com/symfony/cache/blob/7.2/Adapter/AbstractAdapter.php"
    click TagAwareInterface "https://github.com/symfony/cache/blob/7.2/Adapter/TagAwareAdapterInterface.php"
    click ArrayAdapter "https://github.com/symfony/cache/blob/7.2/Adapter/ArrayAdapter.php"
    click NullAdapter "https://github.com/symfony/cache/blob/7.2/Adapter/NullAdapter.php"
    click FilesystemAdapter "https://github.com/symfony/cache/blob/7.2/Adapter/FilesystemAdapter.php"
    click PhpFilesAdapter "https://github.com/symfony/cache/blob/7.2/Adapter/PhpFilesAdapter.php"
    click PdoAdapter "https://github.com/symfony/cache/blob/7.2/Adapter/PdoAdapter.php"
    click DoctrineDbalAdapter "https://github.com/symfony/cache/blob/7.2/Adapter/DoctrineDbalAdapter.php"
    click RedisAdapter "https://github.com/symfony/cache/blob/7.2/Adapter/RedisAdapter.php"
    click MemcachedAdapter "https://github.com/symfony/cache/blob/7.2/Adapter/MemcachedAdapter.php"
    click CouchbaseAdapter "https://github.com/symfony/cache/blob/7.2/Adapter/CouchbaseBucketAdapter.php"
    click ChainAdapter "https://github.com/symfony/cache/blob/7.2/Adapter/ChainAdapter.php"
    click ProxyAdapter "https://github.com/symfony/cache/blob/7.2/Adapter/ProxyAdapter.php"
    click TraceableAdapter "https://github.com/symfony/cache/blob/7.2/Adapter/TraceableAdapter.php"
    click Psr16Bridge "https://github.com/symfony/cache/blob/7.2/Psr16Cache.php"
    click MessengerIntegration "https://github.com/symfony/cache/tree/7.2/Messenger"
    click DataCollector "https://github.com/symfony/cache/blob/7.2/DataCollector/CacheDataCollector.php"
    click DefaultMarshaller "https://github.com/symfony/cache/blob/7.2/Marshaller/DefaultMarshaller.php"
    click DeflateMarshaller "https://github.com/symfony/cache/blob/7.2/Marshaller/DeflateMarshaller.php"
    click SodiumMarshaller "https://github.com/symfony/cache/blob/7.2/Marshaller/SodiumMarshaller.php"
    click DependencyInjection "https://github.com/symfony/cache/tree/7.2/DependencyInjection"
    click ExceptionHandler "https://github.com/symfony/cache/tree/7.2/Exception"
    click EarlyDispatcher "https://github.com/symfony/cache/blob/7.2/Messenger/EarlyExpirationDispatcher.php"
    click EarlyHandler "https://github.com/symfony/cache/blob/7.2/Messenger/EarlyExpirationHandler.php"
    click EarlyMessage "https://github.com/symfony/cache/blob/7.2/Messenger/EarlyExpirationMessage.php"
    click AbstractTagAware "https://github.com/symfony/cache/blob/7.2/Adapter/AbstractTagAwareAdapter.php"
    click TagAwareAdapter "https://github.com/symfony/cache/blob/7.2/Adapter/TagAwareAdapter.php"
    click TagAwareMarshaller "https://github.com/symfony/cache/blob/7.2/Marshaller/TagAwareMarshaller.php"

    %% Styling
    classDef core fill:#2b6cb0,stroke:#1a4971,color:white
    classDef adapter fill:#48bb78,stroke:#2f855a,color:white
    classDef integration fill:#ed8936,stroke:#c05621,color:white
    classDef support fill:#805ad5,stroke:#553c9a,color:white
    classDef expiration fill:#f56565,stroke:#c53030,color:white
    classDef tagaware fill:#4299e1,stroke:#2b6cb0,color:white
```
