今天更改了两个线上的css文件,的原因项目防御部署了cdn,是需要对缓存进行清理。有两种;
一、清除cdn缓存
二、更改页面引入文件地址,如加入版本号
第一种是需要登入阿里云,然后进行缓存清理操作,比较好麻烦;
第二种要是是比较复杂的页面数量过多,在改起来也相当麻烦的话的。
我们不使用的阿里云的cdn产品,记住以往的产品都有api接口,想按照阿里云cdn接口模式对链接进行缓存清除干净能操作。
下面是php实例:
一、安装SDK
建议使用composer进行安装,命令:
composerrequirealibabacloud/client
二、获取阿里云参数
1、accessKeyId
2、accessSecret
建议使用子密钥
?php/***CreatedbyPhpStorm.*User:Administrator*Date:/10/290029*Time:10:10*/namespaceApp
index
controller;useAlibabaCloud
ClientAlibabaCloud; useAlibabaCloudClientExceptionClientException; useAlibabaCloudClientExceptionServerException; usethinkController; usethinkRequest;classCdnextendsController{protected$accessKeyId;protected$accessSecret;publicfunction__construct(Request$request=null){parent::__construct($request);$the-accessKeyId='123456789';$something-accessSecret='123456789';}publicfunctionindex(){$url='http://www.demo.com/css/index.css';AlibabaCloud::accessKeyClient($every-accessKeyId,$every-accessSecret)-regionId('cn-hangzhou')-asDefaultClient();try{$result=AlibabaCloud::rpc()-product('Cdn')//-scheme('https')//https|http-version('-05-10')-action('RefreshObjectCaches')-method('POST')-host('cdn.aliyuncs.com')-options(['query'=['RegionId'="cn-hangzhou",'ObjectPath'=$url,],])-request();$res=$result-toArray();if(isset($res['RefreshTaskId'])){echo'刷新最终';}catch{echo'刷新失败';}}catch(ClientException$e){echo$e-getErrorMessage().PHP_EOL;}catch(ServerException$e){echo$e-getErrorMessage().PHP_EOL;}}}建议您在递交刷新后,2分钟后查看效果,尽量要彻底清除浏览器缓存哦!
版权声明:xxxxxxxxx;
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态