缓存配置
更新时间:2023-05-16
下列代码中对函数入参c即是CdnClient对象,详情参见CdnClient
设置共享缓存
case1:开启共享缓存
def test_set_cache_share_enable(c):
"""
test_set_cache_share_enable
"""
cache_share = {
"enabled": True,
"domain": "test-cache-share.test.com"
}
response = c.set_domain_cache_share('example.test.com', cache_share)
print(response)
case2:关闭共享缓存
def test_set_cache_share_disable(c):
"""
test_set_cache_share_disable
"""
cache_share = {
"enabled": False,
}
response = c.set_domain_cache_share('example.test.com', cache_share)
print(response)
查询共享缓存配置
def test_get_cache_share(c):
"""
test_get_cache_share
"""
response = c.get_domain_cache_share('example.test.com')
print(response)
设置缓存过期规则
def test_set_domain_cache_ttl(self):
"""
test_set_domain_cache_ttl
"""
error = None
try:
rules = []
rules.append({'type':'suffix', 'value': '.jpg', 'ttl': 3600, 'weight': 30}) # .jpg后缀缓存一小时
rules.append({'type':'path', 'value': '/a/b/c', 'ttl': 1800, 'weight': 15}) # /a/b/c/目录下所有文件缓存1800秒
response = self.cdn_client.set_domain_cache_ttl('opencdn3.sys-qa.com', rules)
print response
except BceServerError as e:
error = e
finally:
self.assertIsNone(error)
设置缓存参数过滤规则
def test_set_domain_cache_full_url(self):
"""
test_set_domain_cache_full_url
"""
error = None
try:
response = self.cdn_client.set_domain_cache_full_url('opencdn3.sys-qa.com', True)
print response
except BceServerError as e:
error = e
finally:
self.assertIsNone(error)
查询缓存参数过滤规则
def test_get_domain_cache_full_url(c):
"""
test get domain cache full url
"""
response = c.get_domain_cache_full_url('test-sdk.sys-qa.com')
print(response)
设置自定义错误码页面
def test_set_domain_error_page(c):
"""
test set domain error page
"""
error_page = [
{'code': 404, 'redirectCode':302, 'url': '/customer_404.html'},
{'code': 403, 'url': '/customer_403.html'}
]
domain = 'test-sdk.sys-qa.com'
response = c.set_domain_error_page(domain, error_page);
print(response)
查询自定义错误码页面
def test_get_domain_error_page(c):
"""
test get domain error page
"""
response = c.get_domain_error_page('test-sdk.sys-qa.com')
print(response)