Skip to main content
BreakawayPaul
Inspiring
February 7, 2013
Question

<cfquery> caching

  • February 7, 2013
  • 1 reply
  • 959 views

I have a sidebar item on the front page of my website that pulls a "featured pic" out of my photo gallery and keeps it there for the day.  While it's not really important when that day starts and ends (people are of course, in all different time zones), I'd like to have the pic up for 24-hrs-ish.

I started to write a complicated script to check the date and rotate the pic every day, but then I thought I might do it the "cheap" way, and just cache the query for 24 hrs.   The problem is, if I leave the page and return, I get a completely different pic.  I'm thinking that since my query is in the request scope, the caching is failing because CF sees the query name as being different.

Here's my code:

<cfquery name="FeaturedPic" datasource="#request.dsn#" cachedwithin="#createtimespan(0,24,0,0)#" maxrows="1">

SELECT    photos.pic_id

        , photos.pic_file

        , albums.album_url

        , albums.album_name

        , parents.album_name AS parent

        , parents.album_url AS parenturl

FROM photos

INNER JOIN albums

        ON photos.pic_album = albums.album_id

LEFT JOIN albums AS parents

        ON parents.album_id = albums.parent_album

ORDER BY rand()

</cfquery>

Is my hypothesis about my caching correct, or is there something else I'm missing?

    This topic has been closed for replies.

    1 reply

    Inspiring
    February 7, 2013

    The code you posted shows the query to be in the variables scope, not the request scope.  Turn on de-bugging to see if you are running a cached copy or not.

    BreakawayPaul
    Inspiring
    February 7, 2013

    I can't change any settings (shared hosting), but I can do it locally tonight on my home machine.  I'll see if I can reproduce the problem locally too.  Thanks!