Skip to content

Commit fd57da1

Browse files
committed
index on anywhere-cache-samples: e83ba77 addressing review comments
1 parent bb23814 commit fd57da1

File tree

5 files changed

+55
-35
lines changed

5 files changed

+55
-35
lines changed

storage-control/createAnywhereCache.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@
2323

2424
function main(bucketName, zoneName) {
2525
// [START storage_control_create_anywhere_cache]
26+
2627
/**
27-
* TODO(developer): Uncomment these variables before running the sample.
28+
* Creates an Anywhere Cache instance for a Cloud Storage bucket.
29+
* Anywhere Cache is a feature that provides an SSD-backed zonal read cache.
30+
* This can significantly improve read performance for frequently accessed data
31+
* by caching it in the same zone as your compute resources.
32+
*
33+
* @param {string} bucketName The name of the bucket to create the cache for.
34+
* Example: 'your-gcp-bucket-name'
35+
* @param {string} zoneName The zone where the cache will be created.
36+
* Example: 'us-central1-a'
2837
*/
2938

30-
// The name of your GCS bucket
31-
// const bucketName = 'bucketName';
32-
33-
// The zone that the cache instance will run in.
34-
// const zoneName = 'zoneName';
35-
3639
// Imports the Control library
3740
const {StorageControlClient} = require('@google-cloud/storage-control').v2;
3841

@@ -47,6 +50,8 @@ function main(bucketName, zoneName) {
4750
parent: bucketPath,
4851
anywhereCache: {
4952
zone: zoneName,
53+
ttl: '70000s',
54+
admissionPolicy: 'admit-on-first-miss',
5055
},
5156
};
5257

storage-control/disableAnywhereCache.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@
2424
function main(bucketName, cacheName) {
2525
// [START storage_control_disable_anywhere_cache]
2626
/**
27-
* TODO(developer): Uncomment these variables before running the sample.
27+
* Disables an Anywhere Cache instance.
28+
*
29+
* Disabling a cache is the first step to permanently removing it. Once disabled,
30+
* the cache stops ingesting new data. After a grace period, the cache and its
31+
* contents are deleted. This is useful for decommissioning caches that are no
32+
* longer needed.
33+
*
34+
* @param {string} bucketName The name of the bucket where the cache resides.
35+
* Example: 'your-gcp-bucket-name'
36+
* @param {string} cacheName The unique identifier of the cache instance to disable.
37+
* Example: 'cacheName'
2838
*/
2939

30-
// The name of your GCS bucket
31-
// const bucketName = 'bucketName';
32-
33-
// The name of the cache to be disabled
34-
// const cacheName = 'cacheName';
35-
3640
// Imports the Control library
3741
const {StorageControlClient} = require('@google-cloud/storage-control').v2;
3842

storage-control/getAnywhereCache.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@
2424
function main(bucketName, cacheName) {
2525
// [START storage_control_get_anywhere_cache]
2626
/**
27-
* TODO(developer): Uncomment these variables before running the sample.
27+
* Retrieves details of a specific Anywhere Cache instance.
28+
*
29+
* This function is useful for checking the current state, configuration (like TTL),
30+
* and other metadata of an existing cache.
31+
*
32+
* @param {string} bucketName The name of the bucket where the cache resides.
33+
* Example: 'your-gcp-bucket-name'
34+
* @param {string} cacheName The unique identifier of the cache instance.
35+
* Example: 'my-anywhere-cache-id'
2836
*/
2937

30-
// The name of your GCS bucket
31-
// const bucketName = 'bucketName';
32-
33-
// The name of the cache to get
34-
// const cacheName = 'cacheName';
35-
3638
// Imports the Control library
3739
const {StorageControlClient} = require('@google-cloud/storage-control').v2;
3840

@@ -54,6 +56,15 @@ function main(bucketName, cacheName) {
5456
// Run request
5557
const [response] = await controlClient.getAnywhereCache(request);
5658
console.log(`Got anywhere cache: ${response.name}.`);
59+
console.log(`Anywhere Cache details for '${cacheName}':`);
60+
console.log(` ID: ${response.id}`);
61+
console.log(` Zone: ${response.zone}`);
62+
console.log(` State: ${response.state}`);
63+
console.log(` TTL: ${response.ttl.seconds}s`);
64+
console.log(` Admission Policy: ${response.admissionPolicy}`);
65+
console.log(
66+
` Create Time: ${new Date(response.createTime.seconds * 1000).toISOString()}`
67+
);
5768
}
5869

5970
callGetAnywhereCache();

storage-control/listAnywhereCaches.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
function main(bucketName) {
2626
// [START storage_control_list_anywhere_caches]
2727
/**
28-
* TODO(developer): Uncomment these variables before running the sample.
28+
* Lists all Anywhere Cache instances for a Cloud Storage bucket.
29+
* This function helps you discover all active and pending caches associated with
30+
* a specific bucket, which is useful for auditing and management.
31+
*
32+
* @param {string} bucketName The name of the bucket to list caches for.
33+
* Example: 'your-gcp-bucket-name'
2934
*/
3035

31-
// The name of your GCS bucket
32-
// const bucketName = 'bucketName';
33-
3436
// Imports the Control library
3537
const {StorageControlClient} = require('@google-cloud/storage-control').v2;
3638

storage-control/updateAnywhereCache.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,16 @@
2424
function main(bucketName, cacheName, admissionPolicy) {
2525
// [START storage_control_update_anywhere_cache]
2626
/**
27-
* TODO(developer): Uncomment these variables before running the sample.
27+
* Updates the Admission Policy of an Anywhere Cache instance.
28+
*
29+
* @param {string} bucketName The name of the bucket where the cache resides.
30+
* Example: 'your-gcp-bucket-name'
31+
* @param {string} cacheName The unique identifier of the cache instance to update.
32+
* Example: 'my-anywhere-cache-id'
33+
* @param {string} admissionPolicy Determines when data is ingested into the cache
34+
* Example: 'admit-on-second-miss'
2835
*/
2936

30-
// The name of your GCS bucket
31-
// const bucketName = 'bucketName';
32-
33-
// The name of the cache to be update
34-
// const cacheName = 'cacheName';
35-
36-
// The admission policy of the cache to be updated
37-
// const admissionPolicy = 'admit-on-second-miss';
38-
3937
// Imports the Control library
4038
const {StorageControlClient} = require('@google-cloud/storage-control').v2;
4139

0 commit comments

Comments
 (0)