如何在softlayer"独立cdn +对象存储"?上缓存清除?

时间:2017-04-17 13:44:22

标签: ibm-cloud-infrastructure

我们正在使用softlayer"独立的cdn +对象存储"并试图清除像

这样的网址缓存

HTTP网址

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

HTTPS网址

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

使用

上写的方法

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

但缓存清除无效。 如何在softlayer"独立cdn +对象存储"?上缓存清除? 以下是代码&我们有错误。



--------------------------------------------------------------------------------
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
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

方法SoftLayer_Network_ContentDelivery_Account::purgeCache适用于通过“产品订单”流程创建的CDN对象。正如您在文档中看到的,此方法需要一个InitParameter,它是CDN ID和您要清除缓存的URL。

错误 &#34;对象在&#34; 上执行方法不存在是因为您没有在以下位置指定CDN ID:

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

如果您订购了CDN,您应该可以通过页面https://control.softlayer.com/storage/cdn或通过调用SoftLayer_Account::getCdnAccounts方法查看。如果是这种情况,您可以创建一个&#34;原始拉动映射&#34;使用方法SoftLayer_Network_ContentDelivery_Account::createOriginPullMapping。之后,您应该能够使用purgeCache方法,使用您在createOriginPullMapping期间输入的CNAME。

我无法重现您提供的第二个PHP代码中描述的错误。代码很好,我能够使用相同的代码制作purgeCache,但我注意到以下内容:

以下行代码的结果为真:

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

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

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

最后一个是问题,&#34; /web/test456465.txt"不存在但结果为TRUE。如果在 purgeCache 之前添加方法获取,则为FALSE。

错误可能与 get 方法有关,因为它说: 的 &#39; NoneType&#39;对象没有属性&#39; get&#39;

我建议在 purgeCache 之前添加 get 方法以验证该对象是否存在,您也可以使用以下代码验证它:

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

如果&#39; /web/test.txt'打印它意味着对象存在。

如果错误&#34;无法保存ObjectStorage对象&#34; ,则可以尝试更改位置。

您也可以手动清除缓存,如下所示:

发出如下POST请求:

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

“AUTH_tka456546546546545”是使用CURL时应该得到的X-Auth-Token。见Softlayer Object Storage Auth Endpoint

参考文献:

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

我希望这对你有所帮助。

问候。