<cfquery> caching
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?
