搜索本产品文档关键词
缓存配置
所有文档
menu

内容分发网络 CDN

缓存配置

下列代码中对函数入参c即是CdnClient对象,详情参见CdnClient

设置共享缓存

case1:开启共享缓存

Python
1def test_set_cache_share_enable(c):
2    """
3    test_set_cache_share_enable
4    """
5    cache_share = {
6        "enabled": True,
7        "domain": "test-cache-share.test.com" 
8    }
9    response = c.set_domain_cache_share('example.test.com', cache_share)
10    print(response)

case2:关闭共享缓存

Python
1def test_set_cache_share_disable(c):
2    """
3    test_set_cache_share_disable
4    """
5    cache_share = {
6        "enabled": False,
7    }
8    response = c.set_domain_cache_share('example.test.com', cache_share)
9    print(response)

查询共享缓存配置

Python
1def test_get_cache_share(c):
2    """
3    test_get_cache_share
4    """
5    response = c.get_domain_cache_share('example.test.com')
6    print(response)

设置缓存过期规则

Python
1def test_set_domain_cache_ttl(self):
2    """
3    test_set_domain_cache_ttl
4    """
5    error = None
6    try:
7        rules = []
8        rules.append({'type':'suffix', 'value': '.jpg', 'ttl': 3600, 'weight': 30})    # .jpg后缀缓存一小时
9        rules.append({'type':'path', 'value': '/a/b/c', 'ttl': 1800, 'weight': 15})    # /a/b/c/目录下所有文件缓存1800秒
10        response = self.cdn_client.set_domain_cache_ttl('opencdn3.sys-qa.com', rules)
11        print response
12    except BceServerError as e:
13        error = e
14    finally:
15        self.assertIsNone(error)

设置缓存参数过滤规则

Python
1def test_set_domain_cache_full_url(self):
2    """
3    test_set_domain_cache_full_url
4    """
5    error = None
6    try:
7        response = self.cdn_client.set_domain_cache_full_url('opencdn3.sys-qa.com', True)
8        print response
9    except BceServerError as e:
10        error = e
11    finally:
12        self.assertIsNone(error)

查询缓存参数过滤规则

Python
1def test_get_domain_cache_full_url(c):
2    """
3    test get domain cache full url
4    """
5    response = c.get_domain_cache_full_url('test-sdk.sys-qa.com')
6    print(response)

设置自定义错误码页面

Python
1def test_set_domain_error_page(c):
2    """
3    test set domain error page
4    """
5    error_page = [
6                    {'code': 404, 'redirectCode':302, 'url': '/customer_404.html'},
7                    {'code': 403, 'url': '/customer_403.html'}
8                 ]
9    domain = 'test-sdk.sys-qa.com'
10    response = c.set_domain_error_page(domain, error_page);
11    print(response)

查询自定义错误码页面

Python
1def test_get_domain_error_page(c):
2    """
3    test get domain error page
4    """
5    response = c.get_domain_error_page('test-sdk.sys-qa.com')
6    print(response)
上一篇
日志接口
下一篇
回源配置