Skip to main content
Participant
April 30, 2007
Answered

Can I cache a CFHTTP process within an include?

  • April 30, 2007
  • 4 replies
  • 480 views
Hi,

Can someone please help me with caching advice?

I want to access a snippet of code (from my own server) to include on my CF scripts. Specifically, it is my website header which contains some SSIs (#include). (My site is mostly static with a couple of CF scripts only.)

Sample header code:
quote:

<div id="access">Skip links here</div>

<div id="header">
<div id="logo">logo here</div>
<div id="tools">e.g. help, sitemap, contact us</div>
<div id="banner">pretty graphic here</div>
<!--#include virtual="/sitenav.shtml"-->
</div>


I thought to workaround this by creating a CF include that used CFHTTP to get the fully parsed header then include it into the CF pages. This works but seems inefficient to do a CFHTTP call each time a CF page loads, so I'd like to cache the process. I was going to put the CFCACHE tag in my CF include file, but am not sure this will work as expected as won't this try to cache the whole CF page, rather than just the CFHTTP process within the include? (which is what I want)

Am I approaching this all wrong? Can anyone help?

Thanks in advanced for your help.
This topic has been closed for replies.
Correct answer malkau
This is what we ended up doing - prolly not the best solution and still not cached:

4 replies

malkauAuthorCorrect answer
Participant
August 14, 2007
This is what we ended up doing - prolly not the best solution and still not cached:

malkauAuthor
Participant
May 1, 2007
A friend actually suggested creating a custom tag that takes a static include as input and looks for all the #include lines and replaces them with <cfincludes>

Sounds like it could work... overkill? :-) I probably could use it in other places...
malkauAuthor
Participant
May 1, 2007
The contents of my header include code is in my previous post above.

If I use <cfinclude> to include those contents, then ColdFusion will not parse the line that says <!--#include virtual="/sitenav.shtml"--> It will just appear as a comment in the CF pages.

I could do the following:
quote:

<div id="access">Skip links here</div>
<div id="header">
<div id="logo">logo here</div>
<div id="tools">e.g. help, sitemap, contact us</div>
<div id="banner">pretty graphic here</div>
<!--#include virtual="/sitenav.shtml"-->
<cfinclude template"/sitenav.shtml">
</div>


This would allow the static pages to us the #include then the CF pages use <cfinclude> but then this will make the code on my static pages invalid (am using XHTML strict)

Actually, I have previously used a .CFM include for my header and then used #exec cgi on the static pages to include the code BUT I am on a shared hosting server, and now and then the CF server falls over and I get big JRUN or 500 errors at the top of each static page (looks really unprofessional) so that is why I just use static pages/includes for most of the site content.

So, any advice for me? (besides, get a more reliable host {:-)
Inspiring
April 30, 2007
Can you explain a little more about the reason you're not just using <cfinclude>?