Skip to main content
Known Participant
January 9, 2008
Question

Caching a CFHTTP feed into the Application Scope of the Server

  • January 9, 2008
  • 14 replies
  • 1088 views
Hi

I have the following CFHTTP tag script, how do I check that it is caching this data correctly into the Application scope of the server?

So that users do not have to access the Internet site to get the feed as the CFHTTP caches the data within the 500 minute timeframe set?

This is my Application.cfm page

----
<CFAPPLICATION NAME="application">

<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>

-------------

This is the code to output the feed.

<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)#">

#replace(application.weather_xml.rss.channel.item.title.xmlText, ',', '<br>', 'ALL')#

</cfloop>
</cfoutput>
This topic has been closed for replies.

14 replies

ramboAuthor
Known Participant
January 9, 2008
If I copy all of the images to the root directory of the Coldfusion server, how would it know what image to display ?

Because at present the string looks like

<img src="#application.weather_xml.rss.channel.image.url.xmlText#" alt="#application.weather_xml.rss.channel.item.DESCRIPTION.xmlText#" width="70px" height="70px">

What would I put in <img src=" If I used <img src=" http://127.0.0.1:8500/images/10.gif" then I am hardcoding the image into the page?
BKBK
Community Expert
January 9, 2008
My first instinct is that it has less to do with cfdump and more to do with the broken connection. When you cut internet access the img tag can no longer connect to the URL http://www.bbc.co.uk/weather/images/symbols/animated_sym/10.gif. That URL is the value of the parameter application.weather_xml.rss.channel.image.url.xmlText, which then becomes undefined.

One way to get it to work is to copy the image http://www.bbc.co.uk/weather/images/symbols/animated_sym/10.gif to Coldfusion's root directory, for example. Then use a local URL, thus:

<img src=" http://127.0.0.1:8500/images/10.gif" alt="#application.weather_xml.rss.channel.item.DESCRIPTION.xmlText#" width="70px" height="70px">

ramboAuthor
Known Participant
January 9, 2008
Thanks.

If I try to run the code on a computer with internet access the CFDUMP works.

However if I try and run the code on a computer with no internet access I get the following error

Element WEATHER_XML.RSS.CHANNEL.IMAGE.URL.XMLTEXT is undefined in APPLICATION.

Why is this as the rss data should be stored in the server application memory ?

As I do not want users to go out to this Internet site to retrieve the RSS feed it should be done by the Coldfusion server and then the RSS data displayed on the users browser
BKBK
Community Expert
January 9, 2008
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 every 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.