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

缓存(caches

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

检索所有缓存

要获取应用程序的缓存信息,请向 GET 发起一个 /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

路径 类型 <description> </description>

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

应用程序上下文中以名称为键的缓存。spring-doc.cadn.net.cn

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

Stringspring-doc.cadn.net.cn

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

按名称检索缓存

要按名称检索缓存,请向 GET 发起一个 /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

参数 <description> </description>

cacheManagerspring-doc.cadn.net.cn

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

响应结构

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

路径 类型 <description> </description>

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

清除所有缓存

要清除所有可用的缓存,请向 DELETE 发送一个 /actuator/caches 请求,如下列基于 curl 的示例所示:spring-doc.cadn.net.cn

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

按名称驱逐缓存

要清除特定的缓存,请向 DELETE 发送一个 /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'
由于存在两个名为 countries 的缓存,因此必须提供 cacheManager 来指定应清除哪个 Cache

请求结构

如果所请求的名称足够明确,能够唯一标识一个缓存,则无需额外参数。 否则,必须指定 cacheManager。 下表列出了支持的查询参数:spring-doc.cadn.net.cn

参数 <description> </description>

cacheManagerspring-doc.cadn.net.cn

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