Tuesday, May 13, 2008

Getting Internet Explorer to Release Dataset Cache

Getting I.E. to STOP caching Spry datasets.

This help can be applied to all languages (PHP, ASP, Coldfusion) but since I am primarily a Coldfusion developer, I'll demonstrate how I solved this issue using CFML and JavaScript.

--------------------------------------------------------------------------
File 1. remote.cfc
This file basically returns the XML I will call from Spry
--------------------------------------------------------------------------
<cfcomponent>
<cffunction name="qGetData" access="remote" output="No" returntype="any">
<cfargument name="chatid" required="Yes">

<cfquery name="qGetData" datasource="#DSN#">
SELECT *
FROM chat
WHERE chatid = #ARGUMENTS.chatid#
</cfquery>

<!--- !!!!! IMPORTANT !!!!! --->
<!--- START :: THIS BLOCK OF CODE IS REQUIRED!!! THIS IS WHAT TELLS SPRY TO NOT CACHE THE INCOMING DATA --->
<cfcontent type="text/xml"><!--- I.E. NEEDS THIS --->
<cfheader name="Cache-Control" value= "no-cache">
<cfheader name="Expires" value="0">
<cfheader name="Pragma" value="no-cache">
<!--- END :: THIS BLOCK OF CODE IS REQUIRED!!! THIS IS WHAT TELLS SPRY TO NOT CACHE THE INCOMING DATA --->
<!--- !!!!! IMPORTANT !!!!! --->
<cfset rtrn = "">
<cfxml variable="rtrn">
<chat>
<topic><cfoutput>#qGetData.topic#</cfoutput></topic>
<cfoutput query="qGetData">
<thread>
<date>#DateFormat(qGetData.dtCreated,"m/d/yyyy")#</date>
<time>#TimeFormat(qGetData.dtCreated,"h:mm:ss tt")#</time>
<firstName>#qGetData.first_name#</firstName>
<lastName>#qGetData.last_name#</lastName>
<content><![CDATA[#qGetData.content#]]></content>
</thread>
</cfoutput>
</chat>
</cfxml>

<cfreturn rtrn>
</cffunction>
</cfcomponent>
--------------------------------------------------------------------------

--------------------------------------------------------------------------
File 2. Calling page (chat.cfm)
This file uses Spry to get my dataset from File 1.
--------------------------------------------------------------------------

<cfheader name="Cache-Control" value= "no-cache">
<cfheader name="Expires" value="0">
<cfheader name="Pragma" value="no-cache">
<html>
<head><title>My Chat</title></head>
<script src="/SpryAssets/xpath.js" type="text/javascript"></script>
<script src="/SpryAssets/SpryData.js" type="text/javascript"></script>
<body>
<cfoutput><script language="JavaScript">
//!!!!! IMPORTANT !!!!!
//This variable is appended to the query string to ensure that a cached dataset isn't returned.
var d = new Date().valueOf();
//!!!!! IMPORTANT !!!!!
threads = new Spry.Data.XMLDataSet("/components/remote.cfc?method=qGetData&chatid=#URL.chatid#&cacheBuster=" + d.toString(), //!!!!! IMPORTANT !!!!!
"chat/thread",
{
distinctOnLoad:true,
loadInterval:2000,
useCache:false //this ONLY works in Firefox.
}
);
//The content column needs to be defined as HTML. What a bugger this was to figure out!
threads.setColumnType("content", "html");
</script></cfoutput>

<!--- Output your data! --->
<div spry:region="threads">
<div spry:repeat="threads">
{threads::firstName} says: {threads::time}<br>
<div>{threads::content}</div>
</div>
</div>

</body>
</html>
--------------------------------------------------------------------------

That should do it. EVERYWHERE you see !!!!! IMPORTANT !!!!! you must be sure to do.

Good luck!

Steve Holland
Fusecast

4 comments:

Website laten maken said...

Really good work.. Keep in touch..

Freelance PHP said...

The systems architect creates articles to clothing the needs of the clients. The job vacancies for computer systems may cover consultant,action designers and systems architects.This is an excellent blog because it has good volume of information,everything is described in the simplest manner and all information on this blog is genuine and real to live in.

leap testing said...

This is amazing and wonderful site. These plants show slight movement when an external magnet is positioned close to them. Her experimental art practice was developed in an interdisciplinary capacity with the center. I love this site.

Registered Dietician San Diego said...

It remained questionable how artists and designers interventions are being negotiated in terms of ‘reaching a broader audience’. For instance, employing an antagonistic tone alongside its evocative newness remains politically problematic and ambigious.