Skip to content

Actuator Endpoints

CoCache exposes two Spring Boot Actuator endpoints for runtime monitoring and management of caches. These endpoints are auto-configured by CoCacheEndpointAutoConfiguration when Spring Boot Actuator is on the classpath.

Endpoint Overview

Endpoint IDClassURLPurposeSource
cocacheCoCacheEndpoint/actuator/cocacheCoherent cache management (total, stat, evict, get)CoCacheEndpoint.kt:27
cocacheClientCoCacheClientEndpoint/actuator/cocacheClientClient-side (L2) cache management (size, get, clear)CoCacheClientEndpoint.kt:24

Both endpoints extend AbstractCoCacheEndpoint, which provides a helper method for resolving CoherentCache instances from the CacheFactory.

AbstractCoCacheEndpoint

Base class shared by both endpoint implementations.

AspectDetailSource
Abstract propertycacheFactory: CacheFactory--
Helper methodString.coherentCache(): CoherentCache<String, Any>?Extension on String that looks up a CoherentCache by name
Source File--AbstractCoCacheEndpoint.kt:19

CoCacheEndpoint

The primary management endpoint for Coherent caches. Exposes operations to list all caches, inspect individual caches, evict entries, and retrieve values.

Operations

total() -- List All Caches

AspectDetail
HTTP MethodGET
URL/actuator/cocache
Annotation@ReadOperation
ReturnsList<CacheReport> -- all registered CoherentCache instances
SourceCoCacheEndpoint.kt:30

Filters the CacheFactory.caches map to only include entries where the value is a CoherentCache, then maps each to a CacheReport.

stat(name) -- Cache Statistics

AspectDetail
HTTP MethodGET
URL/actuator/cocache/{name}
Annotation@ReadOperation
Parameter@Selector name: String
ReturnsCacheReport? -- cache details or null if not found
SourceCoCacheEndpoint.kt:40

evict(name, key) -- Evict Cache Entry

AspectDetail
HTTP MethodDELETE
URL/actuator/cocache/{name}/{key}
Annotation@DeleteOperation
Parameters@Selector name: String, @Selector key: String
Returnsvoid
SourceCoCacheEndpoint.kt:45

Evicts an entry from both L2 (client-side) and L1 (distributed) caches, and publishes a CacheEvictedEvent to invalidate the entry across all instances.

get(name, key) -- Get Cache Entry

AspectDetail
HTTP MethodGET
URL/actuator/cocache/{name}/{key}
Annotation@ReadOperation
Parameters@Selector name: String, @Selector key: String
ReturnsCacheValue<*>? -- full cache value with TTL metadata, or null
SourceCoCacheEndpoint.kt:50

CacheReport Data Class

Detailed report of a Coherent cache's configuration and runtime state.

FieldTypeDescriptionSource
nameStringCache nameCoCacheEndpoint.kt:55
clientIdStringDistributed client ID of this instanceCoCacheEndpoint.kt:56
clientSizeLongNumber of entries in the L2 client-side cacheCoCacheEndpoint.kt:57
keyConverterStringString representation of the key converterCoCacheEndpoint.kt:58
distributedCachingStringFully qualified class name of the distributed cache implementationCoCacheEndpoint.kt:59
clientSideCachingStringFully qualified class name of the client-side cache implementationCoCacheEndpoint.kt:60
cacheEvictedEventBusStringFully qualified class name of the event bus implementationCoCacheEndpoint.kt:61
cacheSourceStringFully qualified class name of the cache source implementationCoCacheEndpoint.kt:62
keyFilterStringFully qualified class name of the key filter implementationCoCacheEndpoint.kt:63

Example Response

GET /actuator/cocache

json
[
  {
    "name": "user-cache",
    "clientId": "192.168.1.10",
    "clientSize": 1523,
    "keyConverter": "ToStringKeyConverter(keyPrefix='cocache:user-cache:')",
    "distributedCaching": "me.ahoo.cache.spring.redis.RedisDistributedCache",
    "clientSideCaching": "me.ahoo.cache.client.CaffeineClientSideCache",
    "cacheEvictedEventBus": "me.ahoo.cache.spring.redis.RedisCacheEvictedEventBus",
    "cacheSource": "me.ahoo.cache.api.source.NoOpCacheSource",
    "keyFilter": "me.ahoo.cache.filter.NoOpKeyFilter"
  }
]

CoCacheClientEndpoint

Client-side (L2) cache management endpoint. Provides visibility into the local in-memory cache on the current instance.

Operations

getSize(name) -- Get Client Cache Size

AspectDetail
HTTP MethodGET
URL/actuator/cocacheClient/{name}
Annotation@ReadOperation
Parameter@Selector name: String
ReturnsLong? -- number of entries in the L2 cache, or null if cache not found
SourceCoCacheClientEndpoint.kt:32

get(name, key) -- Get Client Cache Entry

AspectDetail
HTTP MethodGET
URL/actuator/cocacheClient/{name}/{key}
Annotation@ReadOperation
Parameters@Selector name: String, @Selector key: String
ReturnsCacheValue<*>? -- the L2 cache entry with TTL metadata, or null
SourceCoCacheClientEndpoint.kt:37

The key parameter is converted to a string cache key using the cache's KeyConverter before lookup in the client-side cache.

clear(name) -- Clear Client Cache

AspectDetail
HTTP MethodDELETE
URL/actuator/cocacheClient/{name}
Annotation@DeleteOperation
Parameter@Selector name: String
Returnsvoid
SourceCoCacheClientEndpoint.kt:43

Clears all entries from the L2 client-side cache on the current instance only. Does not affect the L1 distributed cache or other instances.

Endpoint Auto-Configuration

CoCacheEndpointAutoConfiguration

Registers both endpoint beans when Spring Boot Actuator is available.

AspectDetailSource
Conditions@AutoConfiguration(after = [CoCacheAutoConfiguration::class]), @ConditionalOnClass(Endpoint::class), @ConditionalOnCoCacheEnabled--
Source File--CoCacheEndpointAutoConfiguration.kt:30
BeanTypeCondition
cocacheEndpointCoCacheEndpoint@ConditionalOnMissingBean
coCacheClientEndpointCoCacheClientEndpoint@ConditionalOnMissingBean

Endpoint Registration Flow

mermaid
sequenceDiagram
autonumber
    participant Boot as Spring Boot
    participant Auto as CoCacheAutoConfiguration
    participant EA as CoCacheEndpointAutoConfiguration
    participant CF as CacheFactory
    participant EP as CoCacheEndpoint
    participant CEP as CoCacheClientEndpoint
    participant Act as Actuator Infrastructure

    Boot->>Auto: Auto-configure CoCache beans
    Auto-->>Boot: CacheFactory, factories, etc.
    Boot->>EA: Auto-configure endpoints
    EA->>CF: Inject CacheFactory
    EA->>EP: new CoCacheEndpoint(cacheFactory)
    EA->>CEP: new CoCacheClientEndpoint(cacheFactory)
    EA-->>Boot: Endpoint beans registered
    Act->>EP: Expose via /actuator/cocache
    Act->>CEP: Expose via /actuator/cocacheClient

Endpoint Architecture

The following diagram shows how the two endpoints relate to the cache layers:

mermaid
graph TB
    subgraph Client["HTTP Client"]
        style Client fill:#161b22,stroke:#6d5dfc,color:#e6edf3
        User["Operator / Monitoring Tool"]
    end

    subgraph Endpoints["Actuator Endpoints"]
        style Endpoints fill:#161b22,stroke:#6d5dfc,color:#e6edf3
        EP["/actuator/cocache<br>CoCacheEndpoint"]
        CEP["/actuator/cocacheClient<br>CoCacheClientEndpoint"]
    end

    subgraph CacheSystem["Cache System"]
        style CacheSystem fill:#161b22,stroke:#6d5dfc,color:#e6edf3
        CF["CacheFactory"]
        CC["CoherentCache"]
        L2["ClientSideCache<br>(L2)"]
        L1["DistributedCache<br>(L1)"]
        Bus["CacheEvictedEventBus"]
    end

    User --> EP
    User --> CEP
    EP --> CF
    CEP --> CF
    CF --> CC
    CC --> L2
    CC --> L1
    CC --> Bus
    EP -- "total/stat" --> CC
    EP -- "evict" --> CC
    EP -- "get" --> CC
    CEP -- "getSize" --> L2
    CEP -- "get" --> L2
    CEP -- "clear" --> L2

Endpoint Operations Summary

The following diagram summarizes all operations available across both endpoints:

mermaid
graph LR
    subgraph CoCacheEP["CoCacheEndpoint"]
        style CoCacheEP fill:#161b22,stroke:#6d5dfc,color:#e6edf3
        OP1["GET /<br>List all caches<br>total()"]
        OP2["GET /{name}<br>Cache statistics<br>stat()"]
        OP3["GET /{name}/{key}<br>Get entry<br>get()"]
        OP4["DELETE /{name}/{key}<br>Evict entry<br>evict()"]
    end

    subgraph ClientEP["CoCacheClientEndpoint"]
        style ClientEP fill:#161b22,stroke:#6d5dfc,color:#e6edf3
        OP5["GET /{name}<br>L2 cache size<br>getSize()"]
        OP6["GET /{name}/{key}<br>L2 entry<br>get()"]
        OP7["DELETE /{name}<br>Clear L2 cache<br>clear()"]
    end

    OP1 -->|"List<CacheReport>"| R1["JSON response"]
    OP2 -->|"CacheReport?"| R2["JSON response"]
    OP3 -->|"CacheValue<*>?"| R3["JSON response"]
    OP4 -->|"void"| R4["Evicted"]
    OP5 -->|"Long?"| R5["JSON response"]
    OP6 -->|"CacheValue<*>?"| R6["JSON response"]
    OP7 -->|"void"| R7["Cleared"]

CoherentCache vs Client Endpoint Usage

ScenarioEndpointOperationURL
Monitor all cachesCoCacheEndpointtotal()GET /actuator/cocache
Inspect single cache configCoCacheEndpointstat(name)GET /actuator/cocache/{name}
Debug a specific cache entryCoCacheEndpointget(name, key)GET /actuator/cocache/{name}/{key}
Force evict across all instancesCoCacheEndpointevict(name, key)DELETE /actuator/cocache/{name}/{key}
Check L2 memory usageCoCacheClientEndpointgetSize(name)GET /actuator/cocacheClient/{name}
Inspect local L2 entryCoCacheClientEndpointget(name, key)GET /actuator/cocacheClient/{name}/{key}
Flush local L2 onlyCoCacheClientEndpointclear(name)DELETE /actuator/cocacheClient/{name}

Enabling Endpoints

By default, Spring Boot Actuator endpoints are not exposed over HTTP. Add the following to your application.yml:

yaml
management:
  endpoints:
    web:
      exposure:
        include: cocache, cocacheClient

Or expose all endpoints:

yaml
management:
  endpoints:
    web:
      exposure:
        include: "*"

Configuration Properties

PropertyTypeDefaultDescriptionSource
cocache.enabledBooleantrueMaster switch for CoCache auto-configuration (including endpoints)CoCacheProperties.kt:24

To disable CoCache (and its endpoints):

yaml
cocache:
  enabled: false

Custom Endpoints

To customize the endpoint beans, simply declare your own @Bean methods in a configuration class. The @ConditionalOnMissingBean annotations on the default beans ensure your custom implementations take precedence:

kotlin
@Configuration
class CustomEndpointConfig {

    @Bean
    fun cocacheEndpoint(cacheFactory: CacheFactory): CoCacheEndpoint {
        // Custom logic before/after
        return CoCacheEndpoint(cacheFactory)
    }
}

Released under the Apache License 2.0.