Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Spanner/metadata/V1/Spanner.php

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions Spanner/samples/V1/SpannerClient/fetch_cache_update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START spanner_v1_generated_Spanner_FetchCacheUpdate_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\ServerStream;
use Google\Cloud\Spanner\V1\CacheUpdate;
use Google\Cloud\Spanner\V1\Client\SpannerClient;
use Google\Cloud\Spanner\V1\FetchCacheUpdateRequest;

/**
* Retrieves a cache update for a given database.
*
* This RPC can be used to warm up the client cache by fetching key recipes
* and server information for a given database. It is recommended to call
* this RPC at the beginning of the client's lifecycle, prior to any other
* data plane operations.
*
* The cache update is returned as a stream because the response can be too
* large to fit into a single `CacheUpdate` message.
*
* @param string $formattedDatabase The database for which to retrieve the cache update. Please see
* {@see SpannerClient::databaseName()} for help formatting this field.
*/
function fetch_cache_update_sample(string $formattedDatabase): void
{
// Create a client.
$spannerClient = new SpannerClient();

// Prepare the request message.
$request = (new FetchCacheUpdateRequest())
->setDatabase($formattedDatabase);

// Call the API and handle any network failures.
try {
/** @var ServerStream $stream */
$stream = $spannerClient->fetchCacheUpdate($request);

/** @var CacheUpdate $element */
foreach ($stream->readAll() as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedDatabase = SpannerClient::databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]');

fetch_cache_update_sample($formattedDatabase);
}
// [END spanner_v1_generated_Spanner_FetchCacheUpdate_sync]
32 changes: 32 additions & 0 deletions Spanner/src/V1/Client/SpannerClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use Google\Cloud\Spanner\V1\BatchWriteRequest;
use Google\Cloud\Spanner\V1\BatchWriteResponse;
use Google\Cloud\Spanner\V1\BeginTransactionRequest;
use Google\Cloud\Spanner\V1\CacheUpdate;
use Google\Cloud\Spanner\V1\CommitRequest;
use Google\Cloud\Spanner\V1\CommitResponse;
use Google\Cloud\Spanner\V1\CreateSessionRequest;
Expand All @@ -49,6 +50,7 @@
use Google\Cloud\Spanner\V1\ExecuteBatchDmlRequest\Statement;
use Google\Cloud\Spanner\V1\ExecuteBatchDmlResponse;
use Google\Cloud\Spanner\V1\ExecuteSqlRequest;
use Google\Cloud\Spanner\V1\FetchCacheUpdateRequest;
use Google\Cloud\Spanner\V1\GetSessionRequest;
use Google\Cloud\Spanner\V1\ListSessionsRequest;
use Google\Cloud\Spanner\V1\Mutation;
Expand Down Expand Up @@ -608,6 +610,36 @@ public function executeStreamingSql(ExecuteSqlRequest $request, array $callOptio
return $this->startApiCall('ExecuteStreamingSql', $request, $callOptions);
}

/**
* Retrieves a cache update for a given database.
*
* This RPC can be used to warm up the client cache by fetching key recipes
* and server information for a given database. It is recommended to call
* this RPC at the beginning of the client's lifecycle, prior to any other
* data plane operations.
*
* The cache update is returned as a stream because the response can be too
* large to fit into a single `CacheUpdate` message.
*
* @example samples/V1/SpannerClient/fetch_cache_update.php
*
* @param FetchCacheUpdateRequest $request A request to house fields associated with the call.
* @param array $callOptions {
* Optional.
*
* @type int $timeoutMillis
* Timeout to use for this call.
* }
*
* @return ServerStream<CacheUpdate>
*
* @throws ApiException Thrown if the API call fails.
*/
public function fetchCacheUpdate(FetchCacheUpdateRequest $request, array $callOptions = []): ServerStream
{
return $this->startApiCall('FetchCacheUpdate', $request, $callOptions);
}

/**
* Gets a session. Returns `NOT_FOUND` if the session doesn't exist.
* This is mainly useful for determining whether a session is still
Expand Down
158 changes: 158 additions & 0 deletions Spanner/src/V1/FetchCacheUpdateRequest.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Spanner/src/V1/gapic_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
"executeStreamingSql"
]
},
"FetchCacheUpdate": {
"methods": [
"fetchCacheUpdate"
]
},
"GetSession": {
"methods": [
"getSession"
Expand Down
3 changes: 3 additions & 0 deletions Spanner/src/V1/resources/spanner_client_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
"ExecuteStreamingSql": {
"timeout_millis": 3600000
},
"FetchCacheUpdate": {
"timeout_millis": 60000
},
"GetSession": {
"timeout_millis": 30000,
"retry_codes_name": "retry_policy_3_codes",
Expand Down
15 changes: 15 additions & 0 deletions Spanner/src/V1/resources/spanner_descriptor_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,21 @@
],
],
],
'FetchCacheUpdate' => [
'grpcStreaming' => [
'grpcStreamingType' => 'ServerStreaming',
],
'callType' => \Google\ApiCore\Call::SERVER_STREAMING_CALL,
'responseType' => 'Google\Cloud\Spanner\V1\CacheUpdate',
'headerParams' => [
[
'keyName' => 'database',
'fieldAccessors' => [
'getDatabase',
],
],
],
],
'GetSession' => [
'callType' => \Google\ApiCore\Call::UNARY_CALL,
'responseType' => 'Google\Cloud\Spanner\V1\Session',
Expand Down
12 changes: 12 additions & 0 deletions Spanner/src/V1/resources/spanner_rest_client_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,18 @@
],
],
],
'FetchCacheUpdate' => [
'method' => 'post',
'uriTemplate' => '/v1/{database=projects/*/instances/*/databases/*}:cacheUpdate',
'body' => '*',
'placeholders' => [
'database' => [
'getters' => [
'getDatabase',
],
],
],
],
'GetSession' => [
'method' => 'get',
'uriTemplate' => '/v1/{name=projects/*/instances/*/databases/*/sessions/*}',
Expand Down
Loading
Loading