跳到主要内容

缓存 (caches)

DeepSeek V3 中英对照 Caches (caches)

caches 端点提供了对应用程序缓存的访问。

获取所有缓存

要检索应用程序的缓存,请向 /actuator/caches 发送一个 GET 请求,如下面的基于 curl 的示例所示:

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

生成的响应类似于以下内容:

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"
}
}
}
}
}
http

响应结构

响应中包含了应用程序缓存的详细信息。下表描述了响应的结构:

路径类型描述
cacheManagersObject按 id 键控的缓存管理器。
cacheManagers.*.cachesObject按名称键控的应用上下文中的缓存。
cacheManagers.*.caches.*.targetString原生缓存的完全限定名。

按名称获取缓存

要通过名称检索缓存,需要向 /actuator/caches/{name} 发起一个 GET 请求,如下面的基于 curl 的示例所示:

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

前面的示例检索了名为 cities 的缓存信息。返回的响应类似于以下内容:

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"
}
http

查询参数

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

参数描述
cacheManager用于限定缓存名称的 cacheManager 名称。如果缓存名称唯一,则可以省略。

响应结构

响应包含了请求的缓存详细信息。下表描述了响应的结构:

路径类型描述
nameString缓存名称。
cacheManagerString缓存管理器名称。
targetString原生缓存的完全限定名称。

清除所有缓存

要清除所有可用的缓存,可以向 /actuator/caches 发起一个 DELETE 请求,如下面基于 curl 的示例所示:

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

按名称清除缓存

要清除特定的缓存,可以向 /actuator/caches/{name} 发送一个 DELETE 请求,如下面基于 curl 的示例所示:

$ curl 'http://localhost:8080/actuator/caches/countries?cacheManager=anotherCacheManager' -i -X DELETE \
-H 'Content-Type: application/x-www-form-urlencoded'
bash
备注

由于存在两个名为 countries 的缓存,因此必须提供 cacheManager 以指定应清除哪个 Cache

请求结构

如果请求的名称足够具体以识别单个缓存,则不需要额外的参数。否则,必须指定 cacheManager。下表列出了支持的查询参数:

参数描述
cacheManager用于限定缓存名称的 cacheManager 名称。如果缓存名称唯一,则可以省略。