快取 (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.