| HTML 캐시는 특정 HTML 페이지 전체가 될수도 있고, 부분일수도 있습니다. 또한 텍스트 형태일수도 있고, XML 형태일수도 잇습니다. 이글에서는 텍스트 파일 형태로 특정 HTML 페이지 전체를 HTML 캐시로 생성해보고자 합니다. 스크립트는 ASP 를 예로 들었습니다. ' ======================================================'  대상 HTML 을 바이너리 형태로 읽어옵니다.
 ' ======================================================
 Function GetHTMLBin(URLaddress)
 Dim Http
 Set Http = CreateObject("Microsoft.XMLHTTP")
 On error resume next
 Http.Open "GET", URLaddress, False
 Http.setRequestHeader "Accept-Language","ko"
 result=Http.SendGetHTMLBin = Http.responseBody
 Set Http = NothingEnd Function
 
 ' ======================================================'  바이너리로 읽어온것을 텍스트로 변환합니다.
 ' ======================================================
 Function BinToText(varBinData, intDataSizeInBytes)    ' as String
 Const adFldLong = &H00000080
 Const adVarChar = 200
 Set objRS = CreateObject("ADODB.Recordset")
 objRS.Fields.Append "txt", adVarChar, intDataSizeInBytes, adFldLong
 objRS.Open
 objRS.AddNew
 objRS.Fields("txt").AppendChunk varBinData
 BinToText = objRS("txt").Value
 objRS.Close
 Set objRS = Nothing
 End Function
 ' ======================================================
 ' 캐시를 생성합니다.
 ' ====================================================== Function make_chche()  Set objFile = Server.CreateObject("Scripting.FileSystemObject") HTMLBin = GetHTMLBin(" http://대상 HTML 파일 주소")
 xml_body = BinToText(HTMLBin,32000)
 strFname = Server.MapPath("서버상에 저장할 캐시 파일명의 상대경로") if objFile.fileExists(strFname) then objFile.DeleteFile(strFname)
 end if
 set out = objFile.CreateTextFile(strFname,true) out.Write("<!-- 캐시 생성 시각 : " & Now() &"-->"&chr(13)&chr(10)&xml_body)
 out.closeset objFile =nothing
 End Function 
 ' ======================================================' 캐시를 읽어옵니다.
 ' ====================================================== Function read_cache()  Set objFile = Server.CreateObject("Scripting.FileSystemObject") strFname = Server.MapPath("읽어올 캐시 파일의 상대경로")
 if objFile.fileExists(strFname) then
 set out = objFile.OpenTextFile(strFname,1)
 str_out = out.ReadAll
   out.closeelse
 str_out = ""
 end if
 read_cache = str_out set objFile = nothingEnd Function
 |