I have a web application that pulls data from template files on the hard-disk of the server. There are about 30-40 different .html files there that it accesses.
I want to cache the data so that I don't have to keep reading and reading the data over and over.
This is my function
VB Code:
Public Function strGetFile(ByVal strFilePath As String, ByVal Server As HttpServerUtility, ByRef State As HttpApplicationState) As String If State.Get(strFilePath) = vbNullString Then Dim objStreamReader As StreamReader = File.OpenText(Server.MapPath(strFilePath)) Dim strRetVal As String = objStreamReader.ReadToEnd() objStreamReader.Close() State.Add(strFilePath, strRetVal) Return strRetVal Else Return State.Get(strFilePath) End If End Function
Previously I just passed in the file path and the Server object (so that I can use MapPath (this code is in a module)).
But now I'm trying to cache the information. I've read up on the ApplicationState class, but it doesn't seem to be remembering the contents of the files. In fact, it seems more Stateless than Stateful....




Reply With Quote