private static void GetIntoCache(string url) { try { var doc = new XmlDocument(); var fullrequesturl = Server + url; var request = (HttpWebRequest)WebRequest.Create(fullrequesturl); var response = (HttpWebResponse)request.GetHttpResponse(); var headers = response.Headers; var status = response.StatusCode; switch (status) { case HttpStatusCode.OK: { doc.Load(response.GetResponseStream()); var lastmodified = headers["Last-Modified"]; var priyomDoc = new PriyomDoc { Url = url, Document = doc, LastModified = lastmodified }; _manager1.Add(url, priyomDoc); break; } case HttpStatusCode.NotFound: { throw new Exception("404"); } default: { throw new Exception("Other failure"); } } } catch (Exception ex) { throw new Exception("Failed to load requested data: " + ex.Message, ex.InnerException); } }
private static void Refreshcache(string url) { try { var priyomDoc = (PriyomDoc)_manager1.GetData(url); var lastmodified = priyomDoc.LastModified; var doc = priyomDoc.Document; var fullrequesturl = Server + url; var request = (HttpWebRequest)WebRequest.Create(fullrequesturl); request.IfModifiedSince = Convert.ToDateTime(lastmodified); var response = (HttpWebResponse)request.GetHttpResponse(); var headers = response.Headers; var status = response.StatusCode; switch (status) { case HttpStatusCode.NotModified: //no need to update break; case HttpStatusCode.OK: { //refresh the cache and reload the doc doc.Load(response.GetResponseStream()); var lastmodified2 = headers["Last-Modified"]; var priyomDoc2 = new PriyomDoc { Url = url, Document = doc, LastModified = lastmodified }; _manager1.Add(url, priyomDoc2); break; } default: { break; } } } catch (Exception ex) { throw new Exception("Failed to load requested data: " + ex.Message, ex.InnerException); } }