对于最新的稳定版本,请使用 Spring Boot 3.4.0spring-doc.cadn.net.cn

缓存 (caches)

cachesendpoint 提供对应用程序缓存的访问。spring-doc.cadn.net.cn

检索所有缓存

要检索应用程序的缓存,请创建一个GETrequest 添加到/actuator/caches,如以下基于 curl 的示例所示:spring-doc.cadn.net.cn

$ curl 'http://localhost:8080/actuator/caches' -i -X GET

生成的响应类似于以下内容:spring-doc.cadn.net.cn

HTTP/1.1 200 OK
Content-Type: application/vnd.spring-boot.actuator.v3+json
Content-Length: 435

{
  "cacheManagers" : {
    "anotherCacheManager" : {
      "caches" : {
        "countries" : {
          "target" : "java.util.concurrent.ConcurrentHashMap"
        }
      }
    },
    "cacheManager" : {
      "caches" : {
        "cities" : {
          "target" : "java.util.concurrent.ConcurrentHashMap"
        },
        "countries" : {
          "target" : "java.util.concurrent.ConcurrentHashMap"
        }
      }
    }
  }
}

响应结构

响应包含应用程序缓存的详细信息。 下表描述了响应的结构:spring-doc.cadn.net.cn

路径 类型 描述

cacheManagersspring-doc.cadn.net.cn

Objectspring-doc.cadn.net.cn

以 id 为键的缓存管理器。spring-doc.cadn.net.cn

cacheManagers.*.cachesspring-doc.cadn.net.cn

Objectspring-doc.cadn.net.cn

应用程序上下文中的缓存(按 name 键控)。spring-doc.cadn.net.cn

cacheManagers.*.caches.*.targetspring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

本机缓存的完全限定名称。spring-doc.cadn.net.cn

按名称检索缓存

要按名称检索缓存,请创建一个GETrequest 添加到/actuator/caches/{name},如以下基于 curl 的示例所示:spring-doc.cadn.net.cn

$ curl 'http://localhost:8080/actuator/caches/cities' -i -X GET

前面的示例检索有关名为cities. 生成的响应类似于以下内容:spring-doc.cadn.net.cn

HTTP/1.1 200 OK
Content-Type: application/vnd.spring-boot.actuator.v3+json
Content-Length: 113

{
  "target" : "java.util.concurrent.ConcurrentHashMap",
  "name" : "cities",
  "cacheManager" : "cacheManager"
}

查询参数

如果请求的名称足够具体,可以识别单个缓存,则不需要额外的参数。 否则,cacheManager必须指定。 下表显示了支持的查询参数:spring-doc.cadn.net.cn

参数 描述

cacheManagerspring-doc.cadn.net.cn

用于限定缓存的 cacheManager 的名称。如果缓存名称是唯一的,则可以省略。spring-doc.cadn.net.cn

响应结构

响应包含请求的缓存的详细信息。 下表描述了响应的结构:spring-doc.cadn.net.cn

路径 类型 描述

namespring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

缓存名称。spring-doc.cadn.net.cn

cacheManagerspring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

缓存管理器名称。spring-doc.cadn.net.cn

targetspring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

本机缓存的完全限定名称。spring-doc.cadn.net.cn

逐出所有缓存

要清除所有可用的缓存,请创建一个DELETErequest 添加到/actuator/caches如以下基于 curl 的示例所示:spring-doc.cadn.net.cn

$ curl 'http://localhost:8080/actuator/caches' -i -X DELETE

按名称逐出缓存

要逐出特定缓存,请创建一个DELETErequest 添加到/actuator/caches/{name}如以下基于 curl 的示例所示:spring-doc.cadn.net.cn

$ curl 'http://localhost:8080/actuator/caches/countries?cacheManager=anotherCacheManager' -i -X DELETE \
    -H 'Content-Type: application/x-www-form-urlencoded'
由于有两个名为countriescacheManager必须提供以指定Cache应该清除。

请求结构

如果请求的名称足够具体,可以识别单个缓存,则不需要额外的参数。 否则,cacheManager必须指定。 下表显示了支持的查询参数:spring-doc.cadn.net.cn

参数 描述

cacheManagerspring-doc.cadn.net.cn

用于限定缓存的 cacheManager 的名称。如果缓存名称是唯一的,则可以省略。spring-doc.cadn.net.cn