Last active
August 29, 2015 17:34
-
-
Save dieseltravis/23970 to your computer and use it in GitHub Desktop.
Caching an XML document with a file dependency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
XmlDocument xDoc = null; | |
string xmlPath = "~/App_Data/SomeXml.xml"; | |
if (HttpContext.Current.Cache[xmlPath] == null) { | |
string cacheFilePath = HttpContext.Current.Server.MapPath(xmlPath); | |
xDoc = new XmlDocument(); | |
xDoc.Load(cacheFilePath); | |
HttpContext.Current.Cache.Insert(xmlPath, xDoc, new CacheDependency(cacheFilePath)); | |
} else { | |
xDoc = (XmlDocument)HttpContext.Current.Cache[xmlPath]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dim xDoc As XmlDocument | |
Dim xmlPath As String = "~/App_Data/SomeXml.xml" | |
If HttpContext.Current.Cache(xmlPath) Is Nothing Then | |
Dim cacheFilePath As String = HttpContext.Current.Server.MapPath(xmlPath) | |
xDoc = New XmlDocument() | |
xDoc.Load(cacheFilePath) | |
HttpContext.Current.Cache.Insert(xmlPath, xDoc, New CacheDependency(cacheFilePath)) | |
Else | |
xDoc = DirectCast(HttpContext.Current.Cache(xmlPath), XmlDocument) | |
End If |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment