diff --git a/docs/userguide/ObjectStore/USERGUIDE.md b/docs/userguide/ObjectStore/USERGUIDE.md index cea15821f..b1f0f1b0d 100644 --- a/docs/userguide/ObjectStore/USERGUIDE.md +++ b/docs/userguide/ObjectStore/USERGUIDE.md @@ -550,6 +550,15 @@ $iosStreamingUrl = $object->getPublicUrl(UrlType::IOS_STREAMING); ``` [ [Get the executable PHP script for this example](/samples/ObjectStore/get-cdn-object-ios-streaming-url.php) ] +### Update CDN Container TTL +You can update the TTL of a CDN-enabled container. + +```php +$cdnContainer = $container->getCdn(); +$cdnContainer->setTtl(); +``` +[ [Get the executable PHP script for this example](/samples/ObjectStore/set-cdn-container-ttl.php) ] + ### Disable CDN Container If you no longer need CDN capabilities for a container, you can disable them. diff --git a/lib/OpenCloud/ObjectStore/Resource/CDNContainer.php b/lib/OpenCloud/ObjectStore/Resource/CDNContainer.php index 44422bf00..80e547349 100644 --- a/lib/OpenCloud/ObjectStore/Resource/CDNContainer.php +++ b/lib/OpenCloud/ObjectStore/Resource/CDNContainer.php @@ -106,4 +106,17 @@ public function isCdnEnabled() { return $this->metadata->getProperty(HeaderConst::ENABLED) == 'True'; } + + /** + * Set the TTL. + * + * @param $ttl The time-to-live in seconds. + * @return \Guzzle\Http\Message\Response + */ + public function setTtl($ttl) + { + $headers = array('X-Ttl' => $ttl); + + return $this->getClient()->post($this->getUrl(), $headers)->send(); + } } diff --git a/samples/ObjectStore/set-cdn-container-ttl.php b/samples/ObjectStore/set-cdn-container-ttl.php new file mode 100644 index 000000000..0ac60674d --- /dev/null +++ b/samples/ObjectStore/set-cdn-container-ttl.php @@ -0,0 +1,47 @@ + getenv('RAX_USERNAME'), + 'apiKey' => getenv('RAX_API_KEY') +)); + +// 2. Obtain an Object Store service object from the client. +$region = 'DFW'; +$objectStoreService = $client->objectStoreService(null, $region); + +// 3. Get CDN-enabled container. +$container = $objectStoreService->getContainer('logos'); +$cdnContainer = $container->getCdn(); + +// 4. Set container metadata. +$cdnContainer->setTtl(4 * 24 * 60 * 60); // 4 days