缓存 (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.