# toss/cache architecture

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

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

## Overview

This deprecated Kotlin/JVM library provides configurable key-value and multi-field caches, with in-memory or Redis-backed resources, plus Spring MVC response caching. The main paths are application calls through CacheManager into cache implementations and repositories, or HTTP requests through the response filter and cache command. The graph reflects explicit SOURCE INDEX references and the sampled filter, manager, repository, and cache implementation excerpts; unsampled subsystem details are represented conservatively.

Main entry points: [`cache-core/src/main/kotlin/im/toss/util/cache/CacheManager.kt`](https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/CacheManager.kt) (Cache manager), [`cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/ResponseCacheFilter.kt`](https://github.com/toss/cache/blob/master/cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/ResponseCacheFilter.kt) (Response cache filter), [`cache-core/src/main/kotlin/im/toss/util/cache/impl/MultiFieldCacheImpl.kt`](https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/impl/MultiFieldCacheImpl.kt) (Multi-field cache), [`cache-core/src/main/kotlin/im/toss/util/cache/CacheResources.kt`](https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/CacheResources.kt) (Resource providers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Cache API"]
  node_manager["Cache manager<br/>[CacheManager.kt]"]
  node_cache_api["Cache interfaces<br/>[Cache.kt]"]
  node_cache_config["Modes and options<br/>[CacheOptions.kt]"]
  node_loaders["Value loaders"]
end

subgraph group_engine["Cache Engine"]
  node_kv_impl["Key-value cache"]
  node_multi_impl["Multi-field cache"]
  node_blocking["Blocking adapters"]
  node_locks["Mutex locking<br/>[MutexLock.kt]"]
end

subgraph group_storage["Storage and Encoding"]
  node_resources["Resource providers<br/>[CacheResources.kt]"]
  node_repository_api["Repository interfaces"]
  node_memory_store[("In-memory store")]
  node_redis_store[("Redis repositories")]
  node_encoding["Serialization<br/>[Serializer.kt]"]
  node_pack["Packed payloads<br/>[Pack.kt]"]
end

subgraph group_web["Spring Integrations"]
  node_spring_config["Spring configuration"]
  node_enable["MVC cache enablement"]
  node_http_client(("HTTP client"))
  node_filter["Response cache filter"]
  node_servlet_app["Servlet handler"]
  node_response_capture["Response capture"]
  node_command["Response cache command<br/>[CacheCommand.kt]"]
  node_eviction["Cache eviction<br/>[EvictCache.kt]"]
  node_identifier["Request identifiers"]
  node_response_support["Response cache support"]
end

node_app(("Kotlin application"))

node_app -->|"requests caches"| node_manager
node_manager -->|"creates"| node_kv_impl
node_manager -->|"creates"| node_multi_impl
node_manager -->|"selects resources"| node_resources
node_manager -->|"configures"| node_cache_config
node_manager -->|"returns cache"| node_cache_api
node_multi_impl -->|"reads and writes"| node_repository_api
node_multi_impl -->|"acquires locks"| node_locks
node_multi_impl -->|"serializes values"| node_encoding
node_cache_api -->|"accepts loaders"| node_loaders
node_blocking -->|"adapts"| node_cache_api
node_resources -->|"provides Redis access"| node_redis_store
node_resources -->|"provides in-memory access"| node_memory_store
node_spring_config -->|"configures"| node_manager
node_enable -->|"enables"| node_spring_config
node_http_client -->|"sends request"| node_filter
node_filter -->|"wraps response"| node_response_capture
node_filter -->|"dispatches request"| node_servlet_app
node_filter -->|"loads cached response"| node_command
node_filter -->|"packs response"| node_pack
node_command -->|"uses loader"| node_blocking
node_command -->|"stores payload"| node_pack
node_eviction -->|"evicts entries"| node_manager
node_response_support -->|"uses cache manager"| node_manager
node_response_support -->|"uses packed data"| node_pack

click node_manager "https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/CacheManager.kt"
click node_cache_api "https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/Cache.kt"
click node_cache_config "https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/CacheOptions.kt"
click node_loaders "https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/CacheValueLoader.kt"
click node_kv_impl "https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/impl/KeyValueCacheImpl.kt"
click node_multi_impl "https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/impl/MultiFieldCacheImpl.kt"
click node_blocking "https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/blocking/BlockingMultiFieldCache.kt"
click node_locks "https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/concurrent/lock/MutexLock.kt"
click node_resources "https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/CacheResources.kt"
click node_repository_api "https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/repository/KeyFieldValueRepository.kt"
click node_memory_store "https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/repository/InMemoryRepository.kt"
click node_redis_store "https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/repository/RedisKeyFieldValueRepository.kt"
click node_encoding "https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/data/serializer/Serializer.kt"
click node_pack "https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/data/container/Pack.kt"
click node_spring_config "https://github.com/toss/cache/blob/master/cache-spring/src/main/kotlin/im/toss/util/cache/spring/TossCacheConfiguration.kt"
click node_enable "https://github.com/toss/cache/blob/master/cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/EnableCacheSupport.kt"
click node_filter "https://github.com/toss/cache/blob/master/cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/ResponseCacheFilter.kt"
click node_response_capture "https://github.com/toss/cache/blob/master/cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/CaptureHttpServletResponse.kt"
click node_command "https://github.com/toss/cache/blob/master/cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/CacheCommand.kt"
click node_eviction "https://github.com/toss/cache/blob/master/cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/EvictCache.kt"
click node_identifier "https://github.com/toss/cache/blob/master/cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/HttpServletRequestCacheIdentifier.kt"
click node_response_support "https://github.com/toss/cache/blob/master/cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/ResponseCacheSupport.kt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_manager,node_cache_api,node_cache_config,node_loaders toneBlue
class node_kv_impl,node_multi_impl,node_blocking,node_locks toneAmber
class node_resources,node_repository_api,node_memory_store,node_redis_store,node_encoding,node_pack toneMint
class node_spring_config,node_enable,node_http_client,node_filter,node_servlet_app,node_response_capture,node_command,node_eviction,node_identifier,node_response_support toneRose
class node_app toneIndigo
```

## Components

### Cache API

- [Cache manager](https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/CacheManager.kt): `cache-core/src/main/kotlin/im/toss/util/cache/CacheManager.kt`
- [Cache interfaces](https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/Cache.kt): `cache-core/src/main/kotlin/im/toss/util/cache/Cache.kt`
- [Modes and options](https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/CacheOptions.kt): `cache-core/src/main/kotlin/im/toss/util/cache/CacheOptions.kt`
- [Value loaders](https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/CacheValueLoader.kt): `cache-core/src/main/kotlin/im/toss/util/cache/CacheValueLoader.kt`

### Cache Engine

- [Key-value cache](https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/impl/KeyValueCacheImpl.kt): `cache-core/src/main/kotlin/im/toss/util/cache/impl/KeyValueCacheImpl.kt`
- [Multi-field cache](https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/impl/MultiFieldCacheImpl.kt): `cache-core/src/main/kotlin/im/toss/util/cache/impl/MultiFieldCacheImpl.kt`
- [Blocking adapters](https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/blocking/BlockingMultiFieldCache.kt): `cache-core/src/main/kotlin/im/toss/util/cache/blocking/BlockingMultiFieldCache.kt`
- [Mutex locking](https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/concurrent/lock/MutexLock.kt): `cache-core/src/main/kotlin/im/toss/util/concurrent/lock/MutexLock.kt`

### Storage and Encoding

- [Resource providers](https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/cache/CacheResources.kt): `cache-core/src/main/kotlin/im/toss/util/cache/CacheResources.kt`
- [Repository interfaces](https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/repository/KeyFieldValueRepository.kt): `cache-core/src/main/kotlin/im/toss/util/repository/KeyFieldValueRepository.kt`
- [In-memory store](https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/repository/InMemoryRepository.kt): `cache-core/src/main/kotlin/im/toss/util/repository/InMemoryRepository.kt`
- [Redis repositories](https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/repository/RedisKeyFieldValueRepository.kt): `cache-core/src/main/kotlin/im/toss/util/repository/RedisKeyFieldValueRepository.kt`
- [Serialization](https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/data/serializer/Serializer.kt): `cache-core/src/main/kotlin/im/toss/util/data/serializer/Serializer.kt`
- [Packed payloads](https://github.com/toss/cache/blob/master/cache-core/src/main/kotlin/im/toss/util/data/container/Pack.kt): `cache-core/src/main/kotlin/im/toss/util/data/container/Pack.kt`

### Spring Integrations

- [Spring configuration](https://github.com/toss/cache/blob/master/cache-spring/src/main/kotlin/im/toss/util/cache/spring/TossCacheConfiguration.kt): `cache-spring/src/main/kotlin/im/toss/util/cache/spring/TossCacheConfiguration.kt`
- [MVC cache enablement](https://github.com/toss/cache/blob/master/cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/EnableCacheSupport.kt): `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/EnableCacheSupport.kt`
- **HTTP client**
- [Response cache filter](https://github.com/toss/cache/blob/master/cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/ResponseCacheFilter.kt): `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/ResponseCacheFilter.kt`
- **Servlet handler**
- [Response capture](https://github.com/toss/cache/blob/master/cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/CaptureHttpServletResponse.kt): `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/CaptureHttpServletResponse.kt`
- [Response cache command](https://github.com/toss/cache/blob/master/cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/CacheCommand.kt): `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/CacheCommand.kt`
- [Cache eviction](https://github.com/toss/cache/blob/master/cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/EvictCache.kt): `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/EvictCache.kt`
- [Request identifiers](https://github.com/toss/cache/blob/master/cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/HttpServletRequestCacheIdentifier.kt): `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/HttpServletRequestCacheIdentifier.kt`
- [Response cache support](https://github.com/toss/cache/blob/master/cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/ResponseCacheSupport.kt): `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/ResponseCacheSupport.kt`

### Other components

- **Kotlin application**

## Connections

- Kotlin application → Cache manager: requests caches (evidence: `cache-core/src/main/kotlin/im/toss/util/cache/CacheManager.kt`)
- Cache manager → Key-value cache: creates (evidence: `cache-core/src/main/kotlin/im/toss/util/cache/CacheManager.kt`)
- Cache manager → Multi-field cache: creates (evidence: `cache-core/src/main/kotlin/im/toss/util/cache/CacheManager.kt`)
- Cache manager → Resource providers: selects resources (evidence: `cache-core/src/main/kotlin/im/toss/util/cache/CacheManager.kt`)
- Cache manager → Modes and options: configures (evidence: `cache-core/src/main/kotlin/im/toss/util/cache/CacheManager.kt`)
- Cache manager → Cache interfaces: returns cache (evidence: `cache-core/src/main/kotlin/im/toss/util/cache/CacheManager.kt`)
- Multi-field cache → Repository interfaces: reads and writes (evidence: `cache-core/src/main/kotlin/im/toss/util/cache/impl/MultiFieldCacheImpl.kt`)
- Multi-field cache → Mutex locking: acquires locks (evidence: `cache-core/src/main/kotlin/im/toss/util/cache/impl/MultiFieldCacheImpl.kt`)
- Multi-field cache → Serialization: serializes values (evidence: `cache-core/src/main/kotlin/im/toss/util/cache/impl/MultiFieldCacheImpl.kt`)
- Cache interfaces → Value loaders: accepts loaders
- Blocking adapters → Cache interfaces: adapts (evidence: `cache-core/src/main/kotlin/im/toss/util/cache/blocking/BlockingMultiFieldCache.kt`)
- Resource providers → Redis repositories: provides Redis access
- Resource providers → In-memory store: provides in-memory access
- Spring configuration → Cache manager: configures (evidence: `cache-spring/src/main/kotlin/im/toss/util/cache/spring/TossCacheConfiguration.kt`)
- MVC cache enablement → Spring configuration: enables (evidence: `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/EnableCacheSupport.kt`)
- HTTP client → Response cache filter: sends request (evidence: `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/ResponseCacheFilter.kt`)
- Response cache filter → Response capture: wraps response (evidence: `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/ResponseCacheFilter.kt`)
- Response cache filter → Servlet handler: dispatches request (evidence: `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/ResponseCacheFilter.kt`)
- Response cache filter → Response cache command: loads cached response (evidence: `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/ResponseCacheFilter.kt`)
- Response cache filter → Packed payloads: packs response (evidence: `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/ResponseCacheFilter.kt`)
- Response cache command → Blocking adapters: uses loader (evidence: `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/CacheCommand.kt`)
- Response cache command → Packed payloads: stores payload (evidence: `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/CacheCommand.kt`)
- Cache eviction → Cache manager: evicts entries (evidence: `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/EvictCache.kt`)
- Response cache support → Cache manager: uses cache manager (evidence: `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/ResponseCacheSupport.kt`)
- Response cache support → Packed payloads: uses packed data (evidence: `cache-spring-webmvc/src/main/kotlin/im/toss/util/cache/spring/webmvc/ResponseCacheSupport.kt`)
