Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Waiting for an Array to be populated

Status
Not open for further replies.

cturland

Programmer
Sep 25, 2000
66
0
0
GB
Hi all,

I'm trying to prevent my web page loading before I've populated a session array. I can't use isdefined because it's normally populated all the time, but the values change from page to page.

Can anyone suggest a way of doing this?

Many thanks,
Carl
 
I'm not understanding you.

The page won't render until all the ColdFusion processing is complete (all variables are set, all CFIFs processed, etc). So there's no need to implicitly wait until an array is populated... it will do that itself.

In fact, you have to jump through some hoops to get ColdFusion to display anything before it's completed the processing of the page. If you're not jumping through those hoops (most notibly CFFLUSH, introduced in CF5.0)... your page will remain white until everything is done.

Or am I missing something?
-Carl
 
Are you asking if you can prevent the page from showing up on the clients browser until the session array is populated?

If so, too my understanding that is not possible. I agree with csteinhilber that the white page will remain visible until the processing of CF is completed.

-jason
 
mmmm, I seem to be having the problem that isnt possible!! :)

I'll try and explain it in more detail.

I have a main page that includes floating frames. When the main page loads, a query is run that populates a session.array. The page within one of the floating frames uses this session.array to display some results, but I have noticed that this page is loaded before my session.array is populated. This is definetly happening because the first time the floating frame page loads it displays incorrect data. When I refreash the frame, the right data appears.

For some reason, the IFrame is definetly being loaded before the session.array has been populated.

*confused*
 
Ok, looked into it a bit more and have realised that the main page does appears to be caching the query I think.

I've tried the usual:

<meta HTTP-EQUIV=&quot;Pragma&quot; CONTENT=&quot;no-cache&quot;>

And I've set my Administrator up as follows:

Template cache size = 0
Limit cached database connection inactive time to 31mins
Limit the maximum number of cached queries on the server to 0

Nothing seems to work though. I have no caching on the actual query in code either.

Any ideas?
 
So... wait a minute... your main page is populating an array that your IFrame is using?? Yeah... I could see where that would cause problems. You kind of left the little part about the IFrames out of your original question ;-)

So... if your session.array always exists, and is usually the same length, then the only way I can see to solve the problem of knowing when it's re-populated is to set some kind of flag. Either in the first element of the array, or in a separate session variable, set a flag to tell you whether the array has the correct data for the current situation. I'm a little at a loss for explaining exactly how to do this, because I'm not sure why you're switching out the data, or what situations warrant re-population, etc... but it would be something like:
Code:
<CFIF iNeedToRepopulateTheArray = true>
   <CFLOCK timeout=&quot;10&quot; throwontimeout=&quot;No&quot; type=&quot;EXCLUSIVE&quot; scope=&quot;SESSION&quot;>
      <CFSET session.repopulatingArray = true>
      <CFSET session.myArray[1] = ...
                  :

      <CFSET session.repopulatingArray = false>
   </CFLOCK>
</CFIF>

           :



<CFSET infiniteCheck = 1>
<CFSET myError = 0>


<CFLOOP condition=&quot;session.repopulatedArray&quot;>
   <CFSET infiniteCheck = infiniteCheck + 1>
   <CFIF infiniteCheck GT 999999>
       <!--- loop is stranded, assume array repopulating failed --->
       <CFSET myError = ...
       <CFSET session.repopulatedArray = false>
   </CFIF>
</CFLOOP>

<CFIF myError EQ 0>
   <!--- set up IFrame here --->
   <CFLOCK timeout=&quot;10&quot; throwontimeout=&quot;No&quot; type=&quot;READONLY&quot; scope=&quot;SESSION&quot;>
       #session.array[1]# ...
   </CFLOCK>
</CFIF>

the other thing that will probably help you are the CFLOCKs.


About the caching issue... first thing you have to do is determine whether it's a page cache or query cache. If it's a query cache,
Code:
<meta HTTP-EQUIV=&quot;Pragma&quot; CONTENT=&quot;no-cache&quot;>
ain't gonna do anything. And if it's a page cache,
Code:
<meta HTTP-EQUIV=&quot;Pragma&quot; CONTENT=&quot;no-cache&quot;>
still might not do anything. I've found that I need a full contingient of cache-busting tags to get anything to not cache. Try:
Code:
<META HTTP-EQUIV=&quot;Pragma&quot; CONTENT=&quot;no-cache&quot;>  
<META HTTP-EQUIV=&quot;cache-control&quot; CONTENT=&quot;no-cache, no-store, must-revalidate&quot;>
<META HTTP-EQUIV=&quot;Expires&quot; CONTENT=&quot;Mon, 01 Jan 1970 23:59:59 GMT&quot;>



-Carl
 
I managed to solve the problem in the end! I moved the populating of the array to my application.cfm. It seems to have solved the problem.

Thanks a lot for your help, it was appreciated! :)

Cheers,
Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top