Skip to content

feat(storagecontrol): add Rapid Cache samples - #2343

Draft
sahusneha2004 wants to merge 2 commits into
mainfrom
storagecontrol-rapid-cache-samples-php
Draft

sahusneha2004 wants to merge 2 commits into
mainfrom
storagecontrol-rapid-cache-samples-php

Conversation

@sahusneha2004

@sahusneha2004 sahusneha2004 commented Nov 2, 2026 •

Copy link
Copy Markdown

Adds Storage Control samples for Rapid Cache, plus a test:

  • create_rapid_cache.php (storage_control_create_rapid_cache): creates a rapid-cache-ultra cache in a zone and waits for the LRO to finish. The server assigns the cache name.
  • get_rapid_cache.php (storage_control_get_rapid_cache)
  • list_rapid_caches.php (storage_control_list_rapid_caches)
  • update_rapid_cache.php (storage_control_update_rapid_cache): sets the TTL with update mask ttl.
  • disable_rapid_cache.php (storage_control_disable_rapid_cache): starts the disable LRO and prints the operation name. It does not wait, because the operation runs for more than an hour.
  • test/rapidCacheTest.php: runs the whole lifecycle on a regional HNS + UBLA bucket, then polls get until the state is disabled. Bucket deletion fails with 409 for a long time after a cache is disabled, so cleanup is best-effort: it retries briefly, then logs the name of any bucket it left behind.
  • Raises google/cloud-storage-control to ^1.12, which has the RapidCache API.

b/482946642

Validation: php-cs-fixer and PHPStan both pass. The live test has not been run yet. Rapid Cache RPCs work only over gRPC, and the authoring environment has no ext-grpc. CI does have it.

[Generated-by: AI]


Update: aligned with googleapis/google-cloud-java#14529

The samples now follow the reference integration test (ITRapidCacheTest). Where this section conflicts with the notes above, this section is current.

  • Create: sets the cache name explicitly to projects/_/buckets/{bucket}/rapidCaches/{zone} (the backend requires the cache ID to equal the zone), with cache_type rapid-cache-ultra and ttl 86400s (24h). It also prints the state.
  • Create / update: wait for the LRO with no time limit (totalPollTimeoutMillis 0). Before, they used the 5-minute client default. If the operation fails, they print the error.
  • Get: also prints the cache type.
  • Disable: now waits for the LRO. An optional $timeoutMillis argument (default 0 = no limit) bounds the wait. If the wait times out, the sample prints that the operation is still running. If the operation fails, it prints the error.
  • Test:
    • Uses cache ID = zone, and waits 20s after creating the bucket.
    • Asserts the cache name, State: running, the cache type, list membership, and TTL 172800s after update.
    • Disables with a 10-minute bound. If the operation isn't done by then, it asserts that get shows State: disabled and does not fail.
    • Teardown disables the cache if the test didn't (errors are ignored), then deletes the bucket on a best-effort basis and logs any leftover bucket.
  • Region tags are unchanged.

Validation: php -l, php-cs-fixer (repo config), and PHPStan (repo config) all pass. The live test was not run locally because ext-grpc is missing in the authoring environment.

[Generated-by: AI]

Adds create, get, list, update and disable Rapid Cache samples for Storage Control, with tests. Bumps google/cloud-storage-control to ^1.12. b/482946642

[Generated-by: AI]
@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Nov 2, 2026
@sahusneha2004 sahusneha2004 added ai-generated Generated by AI storage-sample-architect Generated by storage-sample-architect skill labels Nov 2, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the google/cloud-storage-control dependency and introduces new PHP code samples for managing the lifecycle of Rapid Cache instances, including creation, retrieval, listing, updating, and disabling. It also adds a comprehensive integration test suite. The feedback highlights a PSR-1/PSR-12 style guide violation regarding the test class name casing, and suggests guarding against a potential null pointer dereference in the update sample when retrieving the TTL from the response.

/**
* Tests for the Rapid Cache storage control samples.
*/
class rapidCacheTest extends TestCase

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the PSR-1 and PSR-12 style guides, class names MUST be declared in StudlyCaps. Please rename the class to RapidCacheTest to adhere to these standards. Additionally, the filename should ideally be renamed to RapidCacheTest.php to match the class name.

class RapidCacheTest extends TestCase
References
  1. PSR-1 Section 3 states that class names MUST be declared in StudlyCaps. (link)

/** @var RapidCache $rapidCacheResult */
$rapidCacheResult = $operation->getResult();
printf('Updated Rapid Cache: %s' . PHP_EOL, $rapidCacheResult->getName());
printf('TTL: %d seconds' . PHP_EOL, $rapidCacheResult->getTtl()->getSeconds());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent a potential null pointer dereference (fatal error) if the server does not return the TTL in the response, it is safer to check if the TTL is set before calling getSeconds(). In Protobuf PHP, you can use the hasTtl() method to verify if the message field is populated.

    if ($rapidCacheResult->hasTtl()) {
        printf('TTL: %d seconds' . PHP_EOL, $rapidCacheResult->getTtl()->getSeconds());
    }

…ation test

Set the explicit cache name (ID = zone), cache_type rapid-cache-ultra and ttl 24h on create; wait for the disable LRO; tests assert running state, cache type, list membership and the updated ttl, and bound the disable wait. Aligns with googleapis/google-cloud-java#14529. b/482946642

[Generated-by: AI]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated Generated by AI samples Issues that are directly related to samples. storage-sample-architect Generated by storage-sample-architect skill

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant