Asp cache content - rss caching with asp classic
posted on TUTORIAL
How to cache a content in ASP classic
caching variables and content with simple asp code
after some research i find out how to cache content with classic asp, in this case i needed to cache an rss feed to prevent bandwidth and resource abuse from the external rss source.
here my simple script to read an RSS and to cache the RSS for 6 hours
the core of the script is inside the below lines that write the variable in the application object
Application.Lock
Application(URL) = strHTML
Application(URL+"-time") = Now()
Application.UnLock
the first IF line that simply check if is the case to retrieve the content again or to skip and read the cached content...
If DateDiff("h", Application(URL+"-time"), Now()) >= 6 then
and here all the script to retrieve RSS feed with Caching Content
<%
Sub RSS (URL)
If DateDiff("h", Application(URL+"-time"), Now()) >= 6 then
Set objXML = Server.CreateObject("msxml2.DOMDocument.3.0")
objXML.async = false
objXML.setProperty "ServerHTTPRequest", True
strHTML = strHTML & "<ul>"
' validazione
objXML.validateOnParse =false' true
' non conservare spazi
objXML.preserveWhiteSpace = false
blnLoaded = objXML.Load(URL)
If Not blnLoaded Then
strHTML = strHTML & "<P>ERRORE<br>codice: " & _
objXML.parseError.errorCode & _
"<br>Linea/Col: " & _
objXML.parseError.line & "/" & _
objXML.parseError.linepos & "</P>"
Else
Set objNodeList = objXML.getElementsByTagName("item")
For Each objNode In objNodeList
i = i + 1
if i = 8 then Exit For
For Each objNode2 In objNode.childNodes
Select Case objNode2.nodeName
Case "title"
strTitle = objNode2.firstChild.nodevalue
Case "link"
strURL = objNode2.firstChild.nodevalue
Case "description"
strDescription = objNode2.firstChild.nodevalue
End Select
Next
' mostro a video
strTitle = replace(strTitle,"<br>","<br />")
strDescription = replace(strDescription,"<br>","<br />")
strHTML = strHTML & "<li><a href=""" & strURL & """ target=""_blank"">" & _
strTitle & "</a><br />" & strDescription & "</li>"
strTitle = ""
strURL = ""
strDescription = ""
Next
set objNodeList = Nothing
strHTML = strHTML & "</ul>"
End if
Application.Lock
Application(URL) = strHTML
Application(URL+"-time") = Now()
Application.UnLock
End If
Response.Write(Application(URL))
End sub
%>