隨著 Google Cloud的功能和 API 異動,用戶端程式庫也會隨之更新。用戶端程式庫經常變更,其中許多程式庫每天都會更新及發布。
為獲得最佳支援服務體驗,請務必使用最新版本。許多程式庫都支援語意版本管理,方便您判斷升級需要多少工作量。如果效能降低 (或發生問題),且您使用的是舊版用戶端程式庫,建議升級至新版,充分運用新版的所有改良功能。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eReuse client objects and sessions to improve performance by sharing authentication credentials and reusing access tokens, thus avoiding the overhead of repeated authentication processes.\u003c/p\u003e\n"],["\u003cp\u003ePin dependencies in production environments when installing libraries using package managers like \u003ccode\u003enpm\u003c/code\u003e or \u003ccode\u003epip\u003c/code\u003e to ensure consistent builds and avoid unexpected changes, particularly with beta clients.\u003c/p\u003e\n"],["\u003cp\u003eStay updated with client library releases to benefit from the latest performance improvements and to receive optimal support, as these libraries are frequently updated alongside Google Cloud's capabilities.\u003c/p\u003e\n"]]],[],null,["# Client libraries best practices\n\nThe following are best practices to help you get optimum performance and the best experience\npossible when using both the *Cloud Client Libraries* and the *Google API Client Libraries*.\n\nReuse client objects and sessions\n---------------------------------\n\nWhen making requests with the same library, you should reuse the same client object for many requests when possible, instead of creating a new one for every request. Requests from the same instance will share authentication credential instances.\n\nThe initial request made by an instance of a session client\nperforms authentication, authorization, and access token generation.\nThis processing can take multiple seconds, as it happens over the network.\nFor additional calls on the same client instance, the session client reuses the same access token\nfor as long as it is valid (typically one hour). After it expires, the session client refreshes the access token automatically,\nFor optimal performance, you should reuse the same session client instance for all requests made by your application,\nand allow the client to refresh the access token as needed for all requests needing to run under the same set of credentials.\n\nIn addition, some authentication strategies used by the client libraries have rate limits\nassociated with them. Since each instance of the client has its own credential cache, creating\ntoo many in a small period of time may incur rate limiting causing library requests to fail authentication.\n\nPin dependencies for production\n-------------------------------\n\nWhen installing the libraries from a package manager such as `npm` or `pip` it is important\nto pin the versions using their built-in versioning for production usage. This ensures\nbuilds will consistently use the same versions of these libraries. This is especially\nimportant if you opt to use beta clients which can have their API surface change. The documentation for the relevant library notes this on the library package documentation.\n\nStay up to date\n---------------\n\nAs Google Cloud's capabilities and APIs change, so do the client libraries.\nClient libraries change often with many of them seeing daily updates and releases.\nIn order to get the best possible support experience possible, you should stay up to date\nwith the releases. Many of the libraries support semantic versioning to make it\neasy to determine how much work an upgrade will be. If you are experiencing a degraded\nperformance (or an issue) and you are using an older version of a client library,\nconsider upgrading it to take advantage of all improvements in newer versions."]]