缓存(caches

caches 端点用于访问应用程序的缓存。

获取所有缓存

要获取应用程序的所有缓存,请对 /actuator/caches 发起 GET 请求,如下所示(基于 curl 的示例):

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

返回的响应类似如下:

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

响应结构

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

Path Type Description

cacheManagers

Object

Cache managers keyed by id.

cacheManagers.*.caches

Object

Caches in the application context keyed by name.

cacheManagers.*.caches.*.target

String

Fully qualified name of the native cache.

按名称获取缓存

要按名称获取缓存,请对 /actuator/caches/{name} 发起 GET 请求,如下所示(基于 curl 的示例):

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

上述示例检索了名为 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"
}

查询参数

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

Parameter Description

cacheManager

Name of the cacheManager to qualify the cache. May be omitted if the cache name is unique.

响应结构

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

Path Type Description

name

String

Cache name.

cacheManager

String

Cache manager name.

target

String

Fully qualified name of the native cache.

清空所有缓存

要清空所有可用缓存,请对 /actuator/caches 发起 DELETE 请求,如下所示(基于 curl 的示例):

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

按名称清空缓存

要清空指定缓存,请对 /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'
由于存在两个名为 countries 的缓存,必须提供 cacheManager 以指定要清空的 Cache

请求结构

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

Parameter Description

cacheManager

Name of the cacheManager to qualify the cache. May be omitted if the cache name is unique.