Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 storagecontrol/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require": {
"google/cloud-storage-control": "^1.9"
"google/cloud-storage-control": "^1.12"
},
"require-dev": {
"google/cloud-storage": "^1.48.1"
Expand Down
72 changes: 72 additions & 0 deletions storagecontrol/src/create_rapid_cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?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
*
* http://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.
*/

/**
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storagecontrol/README.md
*/

namespace Google\Cloud\Samples\StorageControl;

# [START storage_control_create_rapid_cache]
use Google\Cloud\Storage\Control\V2\Client\StorageControlClient;
use Google\Cloud\Storage\Control\V2\CreateRapidCacheRequest;
use Google\Cloud\Storage\Control\V2\RapidCache;

/**
* Creates a Rapid Cache instance.
*
* @param string $bucketName The name of your Cloud Storage bucket.
* (e.g. 'my-bucket')
* @param string $zone The zone in which to create the Rapid Cache. The zone
* must be in the same region as the bucket.
* (e.g. 'us-central1-a')
*/
function create_rapid_cache(string $bucketName, string $zone): void
{
$storageControlClient = new StorageControlClient();

// Set project to "_" to signify global bucket
$formattedName = $storageControlClient->bucketName('_', $bucketName);

// Rapid Cache Ultra requires a bucket with hierarchical namespace enabled.
$rapidCache = new RapidCache([
'zone' => $zone,
'cache_type' => 'rapid-cache-ultra',
]);

$request = new CreateRapidCacheRequest([
'parent' => $formattedName,
'rapid_cache' => $rapidCache,
]);

// Creating a Rapid Cache is a long-running operation. This sample blocks
// until it completes.
$operation = $storageControlClient->createRapidCache($request);
$operation->pollUntilComplete();

/** @var RapidCache $rapidCacheResult */
$rapidCacheResult = $operation->getResult();
printf('Created Rapid Cache: %s' . PHP_EOL, $rapidCacheResult->getName());
}
# [END storage_control_create_rapid_cache]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
64 changes: 64 additions & 0 deletions storagecontrol/src/disable_rapid_cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?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
*
* http://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.
*/

/**
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storagecontrol/README.md
*/

namespace Google\Cloud\Samples\StorageControl;

# [START storage_control_disable_rapid_cache]
use Google\Cloud\Storage\Control\V2\Client\StorageControlClient;
use Google\Cloud\Storage\Control\V2\DisableRapidCacheRequest;

/**
* Disables a Rapid Cache instance.
*
* @param string $bucketName The name of your Cloud Storage bucket.
* (e.g. 'my-bucket')
* @param string $rapidCacheId The ID of the Rapid Cache.
* (e.g. 'us-central1-a')
*/
function disable_rapid_cache(string $bucketName, string $rapidCacheId): void
{
$storageControlClient = new StorageControlClient();

// Set project to "_" to signify global bucket
$formattedName = $storageControlClient->rapidCacheName('_', $bucketName, $rapidCacheId);

$request = new DisableRapidCacheRequest([
'name' => $formattedName,
]);

// Disabling a Rapid Cache starts a long-running operation. The cache moves
// to the "disabled" state within seconds, but the operation only completes
// once the cache has been fully removed, which can take more than an hour.
// This sample does not wait for the operation to complete; use
// get_rapid_cache to check the cache state.
$operation = $storageControlClient->disableRapidCache($request);

printf('Disabling Rapid Cache: %s' . PHP_EOL, $formattedName);
printf('Operation: %s' . PHP_EOL, $operation->getName());
}
# [END storage_control_disable_rapid_cache]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
60 changes: 60 additions & 0 deletions storagecontrol/src/get_rapid_cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?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
*
* http://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.
*/

/**
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storagecontrol/README.md
*/

namespace Google\Cloud\Samples\StorageControl;

# [START storage_control_get_rapid_cache]
use Google\Cloud\Storage\Control\V2\Client\StorageControlClient;
use Google\Cloud\Storage\Control\V2\GetRapidCacheRequest;

/**
* Gets a Rapid Cache instance.
*
* @param string $bucketName The name of your Cloud Storage bucket.
* (e.g. 'my-bucket')
* @param string $rapidCacheId The ID of the Rapid Cache.
* (e.g. 'us-central1-a')
*/
function get_rapid_cache(string $bucketName, string $rapidCacheId): void
{
$storageControlClient = new StorageControlClient();

// Set project to "_" to signify global bucket
$formattedName = $storageControlClient->rapidCacheName('_', $bucketName, $rapidCacheId);

$request = new GetRapidCacheRequest([
'name' => $formattedName,
]);

$response = $storageControlClient->getRapidCache($request);

printf('Got Rapid Cache: %s' . PHP_EOL, $response->getName());
printf('Zone: %s' . PHP_EOL, $response->getZone());
printf('State: %s' . PHP_EOL, $response->getState());
}
# [END storage_control_get_rapid_cache]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
59 changes: 59 additions & 0 deletions storagecontrol/src/list_rapid_caches.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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
*
* http://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.
*/

/**
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storagecontrol/README.md
*/

namespace Google\Cloud\Samples\StorageControl;

# [START storage_control_list_rapid_caches]
use Google\Cloud\Storage\Control\V2\Client\StorageControlClient;
use Google\Cloud\Storage\Control\V2\ListRapidCachesRequest;

/**
* Lists Rapid Cache instances for a given bucket.
*
* @param string $bucketName The name of your Cloud Storage bucket.
* (e.g. 'my-bucket')
*/
function list_rapid_caches(string $bucketName): void
{
$storageControlClient = new StorageControlClient();

// Set project to "_" to signify global bucket
$formattedName = $storageControlClient->bucketName('_', $bucketName);

$request = new ListRapidCachesRequest([
'parent' => $formattedName,
]);

$response = $storageControlClient->listRapidCaches($request);

// The iterator handles pagination automatically.
foreach ($response as $rapidCache) {
printf('Rapid Cache name: %s' . PHP_EOL, $rapidCache->getName());
}
}
# [END storage_control_list_rapid_caches]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
81 changes: 81 additions & 0 deletions storagecontrol/src/update_rapid_cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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
*
* http://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.
*/

/**
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/storagecontrol/README.md
*/

namespace Google\Cloud\Samples\StorageControl;

# [START storage_control_update_rapid_cache]
use Google\Cloud\Storage\Control\V2\Client\StorageControlClient;
use Google\Cloud\Storage\Control\V2\RapidCache;
use Google\Cloud\Storage\Control\V2\UpdateRapidCacheRequest;
use Google\Protobuf\Duration;
use Google\Protobuf\FieldMask;

/**
* Updates the time to live (TTL) of a Rapid Cache instance.
*
* @param string $bucketName The name of your Cloud Storage bucket.
* (e.g. 'my-bucket')
* @param string $rapidCacheId The ID of the Rapid Cache.
* (e.g. 'us-central1-a')
* @param int $ttlSeconds The new TTL for cache entries, in seconds. The TTL
* must be between 1 hour and 7 days.
* (e.g. 172800 for 2 days)
*/
function update_rapid_cache(string $bucketName, string $rapidCacheId, int $ttlSeconds): void
{
$storageControlClient = new StorageControlClient();

// Set project to "_" to signify global bucket
$formattedName = $storageControlClient->rapidCacheName('_', $bucketName, $rapidCacheId);

$rapidCache = new RapidCache([
'name' => $formattedName,
'ttl' => new Duration(['seconds' => $ttlSeconds]),
]);

// Only the fields listed in the update mask are changed.
$updateMask = new FieldMask([
'paths' => ['ttl'],
]);

$request = new UpdateRapidCacheRequest([
'rapid_cache' => $rapidCache,
'update_mask' => $updateMask,
]);

// Updating a Rapid Cache is a long-running operation. This sample blocks
// until it completes.
$operation = $storageControlClient->updateRapidCache($request);
$operation->pollUntilComplete();

/** @var RapidCache $rapidCacheResult */
$rapidCacheResult = $operation->getResult();
printf('Updated Rapid Cache: %s' . PHP_EOL, $rapidCacheResult->getName());
printf('TTL: %d seconds' . PHP_EOL, $rapidCacheResult->getTtl()->getSeconds());
Comment thread
sahusneha2004 marked this conversation as resolved.
Resolved
}
# [END storage_control_update_rapid_cache]

// The following 2 lines are only needed to run the samples
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Loading
Loading