Repository navigation
feat(storagecontrol): add Rapid Cache samples #14724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sahusneha2004
merged 5 commits into
main
from
storagecontrol-rapid-cache-samples-python
Nov 18, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9b02da0
feat(storagecontrol): add Rapid Cache samples
sahusneha2004 9716a32
docs(storage): align rapid cache samples with reference integration test
sahusneha2004 8a8bf91
fix(storagecontrol): resolve flake8 import-order lint failures
sahusneha2004 27487d8
fix(storagecontrol): address rapid cache sample review comments
sahusneha2004 0baeaeb
fix(storagecontrol): address Rapid Cache sample review feedback
sahusneha2004 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # 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. | ||
|
|
||
| import sys | ||
|
|
||
| # [START storage_control_create_rapid_cache] | ||
| from google.cloud import storage_control_v2 | ||
|
|
||
|
|
||
| def create_rapid_cache(bucket_name: str, zone: str) -> None: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| # The zone in which to create the Rapid Cache. The zone must be in the | ||
| # same region as the bucket. | ||
| # zone = "us-central1-a" | ||
|
|
||
| storage_control_client = storage_control_v2.StorageControlClient() | ||
| # The storage bucket path uses the global access pattern, in which the "_" | ||
| # denotes this bucket exists in the global namespace. | ||
| project_path = storage_control_client.common_project_path("_") | ||
| bucket_path = f"{project_path}/buckets/{bucket_name}" | ||
|
|
||
| # Only the required fields are set. Optional fields, such as the time to | ||
| # live (TTL) for cache entries, use server defaults and can be changed | ||
| # later by updating the Rapid Cache. | ||
| # Rapid Cache Ultra requires a regional bucket with hierarchical namespace | ||
| # enabled. | ||
| rapid_cache = storage_control_v2.RapidCache( | ||
| zone=zone, | ||
| cache_type="rapid-cache-ultra", | ||
| ) | ||
| request = storage_control_v2.CreateRapidCacheRequest( | ||
| parent=bucket_path, | ||
| rapid_cache=rapid_cache, | ||
| ) | ||
|
|
||
| # Creating a Rapid Cache is a long-running operation. | ||
| operation = storage_control_client.create_rapid_cache(request=request) | ||
| response = operation.result() | ||
|
|
||
| print(f"Created Rapid Cache: {response.name}") | ||
| print(f"State: {response.state}") | ||
| print(f"Cache type: {response.cache_type}") | ||
|
|
||
|
|
||
| # [END storage_control_create_rapid_cache] | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| create_rapid_cache(bucket_name=sys.argv[1], zone=sys.argv[2]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # 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. | ||
|
|
||
| import sys | ||
|
|
||
| # [START storage_control_disable_rapid_cache] | ||
| from google.cloud import storage_control_v2 | ||
|
|
||
|
|
||
| def disable_rapid_cache(bucket_name: str, cache_id: str) -> None: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| # The ID of the Rapid Cache | ||
| # cache_id = "us-central1-a" | ||
|
|
||
| storage_control_client = storage_control_v2.StorageControlClient() | ||
| # The storage bucket path uses the global access pattern, in which the "_" | ||
| # denotes this bucket exists in the global namespace. | ||
| rapid_cache_path = storage_control_client.rapid_cache_path( | ||
| project="_", bucket=bucket_name, rapid_cache=cache_id | ||
| ) | ||
|
|
||
| request = storage_control_v2.DisableRapidCacheRequest(name=rapid_cache_path) | ||
|
|
||
| # Disabling a Rapid Cache is a long-running operation. The cache moves to | ||
| # the "disabled" state quickly, but the operation only completes once the | ||
| # cache is fully removed (which can take more than an hour; bucket deletion | ||
| # is blocked until removal completes). Start the operation without waiting | ||
| # and use get_rapid_cache to check the cache state. | ||
| operation = storage_control_client.disable_rapid_cache(request=request) | ||
|
|
||
| print(f"Disabling Rapid Cache: {rapid_cache_path}") | ||
| print(f"Operation: {operation.operation.name}") | ||
|
|
||
|
|
||
| # [END storage_control_disable_rapid_cache] | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| disable_rapid_cache(bucket_name=sys.argv[1], cache_id=sys.argv[2]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # 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. | ||
|
|
||
| import sys | ||
|
|
||
| # [START storage_control_get_rapid_cache] | ||
| from google.cloud import storage_control_v2 | ||
|
|
||
|
|
||
| def get_rapid_cache(bucket_name: str, cache_id: str) -> None: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| # The ID of the Rapid Cache | ||
| # cache_id = "us-central1-a" | ||
|
|
||
| storage_control_client = storage_control_v2.StorageControlClient() | ||
| # The storage bucket path uses the global access pattern, in which the "_" | ||
| # denotes this bucket exists in the global namespace. | ||
| rapid_cache_path = storage_control_client.rapid_cache_path( | ||
| project="_", bucket=bucket_name, rapid_cache=cache_id | ||
| ) | ||
|
|
||
| request = storage_control_v2.GetRapidCacheRequest(name=rapid_cache_path) | ||
| response = storage_control_client.get_rapid_cache(request=request) | ||
|
|
||
| print(f"Got Rapid Cache: {response.name}") | ||
| print(f"Zone: {response.zone}") | ||
| print(f"State: {response.state}") | ||
| print(f"Cache type: {response.cache_type}") | ||
|
sahusneha2004 marked this conversation as resolved.
Resolved
|
||
| if response.ttl: | ||
| print(f"TTL: {response.ttl.total_seconds():.0f} seconds") | ||
|
|
||
|
|
||
| # [END storage_control_get_rapid_cache] | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| get_rapid_cache(bucket_name=sys.argv[1], cache_id=sys.argv[2]) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # 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. | ||
|
|
||
| import sys | ||
|
|
||
| # [START storage_control_list_rapid_caches] | ||
| from google.cloud import storage_control_v2 | ||
|
|
||
|
|
||
| def list_rapid_caches(bucket_name: str) -> None: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| storage_control_client = storage_control_v2.StorageControlClient() | ||
| # The storage bucket path uses the global access pattern, in which the "_" | ||
| # denotes this bucket exists in the global namespace. | ||
| project_path = storage_control_client.common_project_path("_") | ||
| bucket_path = f"{project_path}/buckets/{bucket_name}" | ||
|
|
||
| request = storage_control_v2.ListRapidCachesRequest(parent=bucket_path) | ||
|
|
||
| # The returned pager handles pagination automatically. | ||
| page_result = storage_control_client.list_rapid_caches(request=request) | ||
| for rapid_cache in page_result: | ||
| print(rapid_cache.name) | ||
|
|
||
| print(f"Listed Rapid Caches in bucket {bucket_name}") | ||
|
|
||
|
|
||
| # [END storage_control_list_rapid_caches] | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| list_rapid_caches(bucket_name=sys.argv[1]) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.