# ifbars/pcache architecture

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

- Interactive diagram: https://gitdiagram.com/ifbars/pcache
- Repository: https://github.com/ifbars/pcache

## Overview

##### Main components
- Consumer Application (any .NET host that references PCache)
- PCache Library (the .csproj you build and publish)
– PCache (public façade)
– CacheEntry (data structure holding cached object + metadata)
– In‐Memory Store (Dictionary<string, CacheEntry>)
– Persistence Handler (serializes/deserializes CacheEntry collection)
- File System (directory/profile where the cache file is saved/loaded)
- .NET Runtime (CLR hosting PCache code)

##### Relationships and data flows
– → In‐Memory Store (on Cache and Retrieve calls)
– → Persistence Handler (on Load and on any Save triggers)
- From Persistence Handler → File System (read/write cache file)

##### Architectural patterns
- Façade Pattern: PCache exposes a simple API hiding the dictionary + file logic
- Repository-style Store: the in‐memory dictionary behaves like a key/value repository
- Persistence Strategy: swap-in a different serializer by extending Persistence Handler
- Single-Responsibility: CacheEntry only holds data + expiry metadata

##### Technology and framework details
- .NET 6 / C# 10
- System.IO for file I/O
- System.Text.Json or BinaryFormatter (specify your chosen serializer)
- PCache.csproj → targets net6.0, outputs PCache.dll

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Actors
    subgraph "External Actors"
        direction TB
        ConsumerApp["Consumer Application"]:::external
        DotNet[".NET 6 CLR"]:::external
        FS["File System"]:::external
    end

    %% PCache Library internals
    subgraph "PCache Library" 
        direction TB
        Facade["PCache (Public Façade)"]:::internal
        Memory["Dictionary<string, CacheEntry>"]:::internal
        Persist["JSON/Binary Serializer (Persistence Handler)"]:::internal
        Entry["CacheEntry<br/>(data + metadata)"]:::internal
    end

    %% Project Artifacts
    subgraph "Project Artifacts"
        direction TB
        csproj["PCache.csproj"]:::artifact
        façadeFile["PCache.cs"]:::artifact
        entryFile["CacheEntry.cs"]:::artifact
        profile["FolderProfile.pubxml"]:::artifact
        output["bin/Release/net6.0/publish/"]:::artifact
        readme["README.md"]:::artifact
    end

    %% Data Flows and Relationships
    ConsumerApp -->|"Load()/Cache()/Retrieve()"| Facade
    DotNet -->|"hosts"| Facade
    Facade -->|"Cache()/Retrieve()"| Memory
    Facade -->|"Save()/Load()"| Persist
    Memory -->|"stores"| Entry
    Persist -->|"uses"| Entry
    Persist -->|"Serialize/Save"| FS
    FS -->|"Deserialize/Load"| Persist

    %% Click Events
    click csproj "https://github.com/ifbars/pcache/blob/main/PCache.csproj"
    click façadeFile "https://github.com/ifbars/pcache/blob/main/PCache.cs"
    click entryFile "https://github.com/ifbars/pcache/blob/main/CacheEntry.cs"
    click profile "https://github.com/ifbars/pcache/blob/main/Properties/PublishProfiles/FolderProfile.pubxml"
    click output "https://github.com/ifbars/pcache/tree/main/bin/Release/net6.0/publish/"
    click readme "https://github.com/ifbars/pcache/blob/main/README.md"

    %% Styles
    classDef external fill:#c2f0c2,stroke:#333,stroke-width:1px
    classDef internal fill:#d0e0ff,stroke:#333,stroke-width:1px
    classDef artifact fill:#f5f5f5,stroke:#999,stroke-dasharray:2 2,stroke-width:1px
```
