/// <summary> /// 刷新cdn缓存 /// </summary> public bool RefreshObjectCache(string cdnDomain, string key, out string requestId, out string taskIdOrMsg, string objectType = "File", string regionId = "cn-hangzhou") { try { var request = new RefreshObjectCachesRequest() { ObjectPath = string.Format("{0}/{1}", cdnDomain, key), ObjectType = objectType, }; var profile = DefaultProfile.GetProfile(regionId, _accessKeyId, _accessKeySecret); var client = new DefaultAcsClient(profile); var response = client.DoAction(request); var xmlTxt = ConvertToString(response.Content); var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlTxt); if (response.Status == 200) { var firstNode = xmlDoc.SelectSingleNode("RefreshObjectCachesResponse"); requestId = firstNode.SelectSingleNode("RequestId").InnerText; taskIdOrMsg = firstNode.SelectSingleNode("RefreshTaskId").InnerText; return(true); } else { var firstNode = xmlDoc.SelectSingleNode("Error"); requestId = firstNode.SelectSingleNode("RequestId").InnerText; taskIdOrMsg = string.Format("{0} : {1}", firstNode.SelectSingleNode("Code").InnerText, firstNode.SelectSingleNode("Message").InnerText); return(false); } } catch (Exception ex) { requestId = string.Empty; taskIdOrMsg = ex.Message; return(false); } }
/// <summary> /// 刷新CDN缓存 /// </summary> /// <param name="path"></param> /// <param name="type"></param> public static void Refresh(string path, string type = "File") { //RefreshObjectCachesRequest RefreshObjectCachesRequest refreshObjectCachesRequest = new RefreshObjectCachesRequest(); refreshObjectCachesRequest.ObjectType = type; refreshObjectCachesRequest.ObjectPath = path; refreshObjectCachesRequest.AcceptFormat = FormatType.JSON; try { var httpResponse = client.DoAction(refreshObjectCachesRequest); if (httpResponse.Status != 200) { throw new HttpRequestException(string.Format("刷新CDN缓存失败,Path:{0}", path)); } } catch (WebException ex) { //记录日志:刷新CDN缓存失败 LogHelper.ErrorFormat($"刷新CDN缓存失败。Path:{path};异常消息:{ex.Message},异常堆栈:{ex.StackTrace}"); } }
/// <summary> /// 刷新缓存 /// </summary> public void RefreshObjectCaches() { RefreshObjectCachesRequest request = new RefreshObjectCachesRequest(); request.ObjectType = ObjectType.File.ToString(); request.ObjectPath = "www.yourdomain.com/1.txt"; try { RefreshObjectCachesResponse response = client.Execute(request); if (string.IsNullOrEmpty(response.Code)) {//刷新成功 } else {//刷新失败 String errorCode = response.Code;//取得错误码 String message = response.Message;//取得错误信息 } } catch (Exception e) { // TODO: handle exception } }
/// <summary> /// 刷新缓存 /// </summary> public void RefreshObjectCaches() { RefreshObjectCachesRequest request = new RefreshObjectCachesRequest(); request.ObjectType = ObjectType.File.ToString(); request.ObjectPath = "www.yourdomain.com/1.txt"; try { RefreshObjectCachesResponse response = client.Execute(request); if (string.IsNullOrEmpty(response.Code)) {//刷新成功 } else { //刷新失败 String errorCode = response.Code; //取得错误码 String message = response.Message; //取得错误信息 } } catch (Exception e) { // TODO: handle exception } }