macromedia.coldfusion.advanced_techniques
[Top] [All Lists]

Re: Caching a CFHTTP feed into the Application Scope of the Server

Subject: Re: Caching a CFHTTP feed into the Application Scope of the Server
From: "BKBK"
Date: Wed, 9 Jan 2008 12:10:14 +0000 UTC
Newsgroups: macromedia.coldfusion.advanced_techniques

I love your application. It deserves a page of its own. Every page of your site 
starts by including the Application.cfm code. I am assuming that you would not 
want the weather code to run on overy page. Also, you should beef up your 
cfapplication tag a little. Here is an idea. The second test answers your 
question about caching, and says more besides.



  

 <!---
 Application.cfm
 =============
 --->
 <cfapplication name = "bbcWeatherFeedApp"                          
 applicationTimeout = "#createTimespan(1,0,0,0)#"                               
                          
 sessionManagement = "yes"                        
 sessionTimeout = "#createTimeSpan(0,0,20,0)#"     
 setClientCookies = "true"> 


 <!---
 bbcWeatherFeed.cfm
 ==================
 --->
 <cfif not structKeyExists(Application, "TimeStamp") or (dateDiff("n", 
Application.TimeStamp, now()) gt 500)> 
        <cfset Application.TimeStamp = now() />
        <cfhttp url="http://feeds.bbc.co.uk/weather/feeds/rss/5day/id/3314.xml"; 
method="GET" resolveurl="No"></cfhttp>
        <cfset Application.weather_xml = xmlParse(cfhttp.FileContent) />
 </cfif>
 <cfoutput>
        <img src="#application.weather_xml.rss.channel.image.url.xmlText#" 
alt="#application.weather_xml.rss.channel.item.DESCRIPTION.xmlText#" 
width="70px" height="70px">
        <br>
        <cfloop index="x" from="1" 
to="#ArrayLen(application.weather_xml.rss.channel.item)#">
                
<p>#replace(application.weather_xml.rss.channel.item[x].title.xmlText, ',', 
'<br>', 'ALL')#</p>
        </cfloop>
 </cfoutput>
 <p>
 <strong>Test 1:</strong> application.timestamp was set/cached 
<cfoutput>#dateDiff('n', Application.TimeStamp, now())#</cfoutput> minutes ago.
 </p>
 <p>
 <strong>Test 2:</strong> Application scope dump
 <cfdump var="#application#">
 </p>


<Prev in Thread] Current Thread [Next in Thread>