缓存 (caches)

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

检索所有缓存

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

$ curl 'https://: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"
        }
      }
    }
  }
}

响应结构

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

路径 类型 描述

cacheManagers

对象

按 ID 键控的缓存管理器。

cacheManagers.*.caches

对象

应用程序上下文中按名称键控的缓存。

cacheManagers.*.caches.*.target

字符串

原生缓存的完全限定名。

按名称检索缓存

要按名称检索缓存,请向 /actuator/caches/{name} 发送 GET 请求,如以下基于 curl 的示例所示:

$ curl 'https://: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

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

查询参数

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

参数 描述

cacheManager

用于限定缓存的缓存管理器名称。如果缓存名称是唯一的,则可以省略。

响应结构

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

路径 类型 描述

name

字符串

缓存名称。

cacheManager

字符串

缓存管理器名称。

target

字符串

原生缓存的完全限定名。

逐出所有缓存

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

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

按名称逐出缓存

要逐出特定缓存,请向 /actuator/caches/{name} 发送 DELETE 请求,如以下基于 curl 的示例所示:

$ curl 'https://:8080/actuator/caches/countries?cacheManager=anotherCacheManager' -i -X DELETE \
    -H 'Content-Type: application/x-www-form-urlencoded'
由于存在两个名为 countries 的缓存,因此必须提供 cacheManager 以指定应清除哪个 Cache

请求结构

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

参数 描述

cacheManager

用于限定缓存的缓存管理器名称。如果缓存名称是唯一的,则可以省略。

© . This site is unofficial and not affiliated with VMware.