1

we are using softlayer's "standalone cdn + object storage" and trying to purge the cache of a url like

HTTP URL

http:// 000aa.http.cdn.softlayer.net/00000AA/tok02/v1/AUTH_secretsecretsecretsecretsecretsecret/web/test.txt

HTTPS URL

https:// 000aa.https.cdn.softlayer.net/00000AA/tok02/v1/AUTH_secretsecretsecretsecretsecretsecret/web/test.txt

using a method written on

REFERENCE http://sldn.softlayer.com/reference/services/SoftLayer_Network_ContentDelivery_Account/purgeCache

but the cache purge is not working. how can i cache purge on softlayer's "standalone cdn + object storage"? following are codes & errors that we have.

--------------------------------------------------------------------------------
softlayer-api-php-client
--------------------------------------------------------------------------------
■code
<?php
$apiUsername = 'SL0000000’;
$apiKey = '0000000000000000000000000000000000000000000000000000000000000000';
$client = SoftLayer\SoapClient::getClient('SoftLayer_Network_ContentDelivery_Account', null, $apiUsername, $apiKey);
$client->purgeCache( array( 'http:// 000aa.http.cdn.softlayer.net/00000AA/tok02/v1/AUTH_secretsecretsecretsecretsecretsecret/web/test.txt' ) );
exit;

■error
PHP Fatal error:  Uncaught SoapFault exception: [SoftLayer_Exception] Object does not exist to execute method on. (SoftLayer_Network_ContentDelivery_Account::purgeCache) in /softlayer-api-php-client-master/src/SoapClient.php:202
Stack trace:
#0 /softlayer-api-php-client-master/src/SoapClient.php(202): SoapClient->__call('purgeCache', Array, NULL, Array, Array)
#1 /softlayer-api-php-client-master/example.php(80): SoftLayer\SoapClient->__call('purgeCache', Array)
#2 /softlayer-api-php-client-master/example.php(80): SoftLayer\SoapClient->purgeCache(Array)
#3 {main}




--------------------------------------------------------------------------------
softlayer-object-storage-php
--------------------------------------------------------------------------------
■code
$options = array('adapter' => ObjectStorage_Http_Client::SOCKET, 'timeout' => 10);
$host = 'https://tok02.objectstorage.softlayer.net';
$username = 'SLOS0000000-0:SL0000000’;
$password = '0000000000000000000000000000000000000000000000000000000000000000';
$objectStorage = new ObjectStorage( $host, $username, $password, $options);
$objectStorage->with('web/test.txt')->purgeCache();

■error
[17-Apr-2017 18:24:04 Asia/Tokyo] PHP Fatal error:  Uncaught exception 'ObjectStorage_Exception_Http_MethodNotAllowed' with message 'Failed to save ObjectStorage Object. 'NoneType' object has no attribute 'get'' in /softlayer-object-storage-php-master/lib/ObjectStorage.php:589
Stack trace:
#0 /softlayer-object-storage-php-master/lib/ObjectStorage.php(589): ObjectStorage_Exception_Http::factory('Failed to save ...', 405)
#1 /softlayer-object-storage-php-master/lib/ObjectStorage/Object.php(71): ObjectStorage->update(Object(ObjectStorage_Object))
#2 /softlayer-object-storage-php-master/example.php(91): ObjectStorage_Object->purgeCache()
#3 {main}
  thrown in /softlayer-object-storage-php-master/lib/ObjectStorage.php on line 589

1 Answers1

0

The method SoftLayer_Network_ContentDelivery_Account::purgeCache works for CDN objects that were created through the Product Order process. As you can see in the documentation this method requires an InitParameter which is the CDN id and the URL you want to purge the Cache.

The error "Object does not exist to execute method on" is because you didn't specified the CDN id in:

$client = SoftLayer\SoapClient::getClient('SoftLayer_Network_ContentDelivery_Account', [ID], $apiUsername, $apiKey);

If you have ordered a CDN you should be able to see it through the page https://control.softlayer.com/storage/cdn or by calling the method SoftLayer_Account::getCdnAccounts. If this is your case, you can create a "origin pull mapping" by using the method SoftLayer_Network_ContentDelivery_Account::createOriginPullMapping. After that, you should be able to use purgeCache method, use the CNAME you entered during createOriginPullMapping.

I couldn't reproduce the error described in the second PHP code you provided. The code is fine, I was able to make a purgeCache using same code, but I noticed the following:

Result is true for following line codes:

$result = $objectStorage->with('/web/test.txt')->get()->purgeCache();

$result = $objectStorage->with('/web/test.txt')->purgeCache(); 

$result = $objectStorage->with('/web/test456465.txt')->purgeCache();       

The last one is an issue, "/web/test456465.txt" doesn't exist but result is TRUE. It is FALSE when is added the method get before purgeCache.

The error could be related to get method, because it says: 'NoneType' object has no attribute 'get'

I suggest to add get method before to purgeCache in order to verify that object exists, also you can verify it by using following line code:

$result = $objectStorage->with('/web/test.txt')->get()->getPath();
print $result;

If '/web/test.txt' is printed it means that object exists.

If the error "Failed to save ObjectStorage Object" persists, you can try by changing the location.

Also you can purge the cache manually as following:

Make a POST request as following:

POST: https://000aa.https.cdn.softlayer.net/00000AA/tok02/v1/AUTH_secretsecretsecretsecretsecretsecret/web/test.txt

Headers:
X-Context: cdn
X-Auth-Token: AUTH_tka456546546546545
X-Cdn-Purge: true

Where “AUTH_tka456546546546545” is the X-Auth-Token you should have been gotten when using CURL. See Softlayer Object Storage Auth Endpoint

References:

https://sldn.softlayer.com/reference/Object-Storage-CDN

http://sldn.softlayer.com/blog/waelriac/managing-softlayer-object-storage-through-rest-apis

https://sldn.softlayer.com/node/272962

https://sldn.softlayer.com/taxonomy/term/61

https://github.com/softlayer/softlayer-object-storage-php

I hope this help you.

Regards.

Community
  • 1
  • 1
Albert Camacho
  • 1,129
  • 1
  • 7
  • 13
  • hello Albert. thank you for answering my question. and YES, your answer helped us a lot to solve the problem! finally, we were able to cache purge on softlayer's “standalone cdn + object storage”. we could not accomplish this without you. THANK YOU SO MUCH!!! – user7878786 Apr 18 '17 at 07:48