9 Replies Latest reply on Apr 6, 2017 6:54 AM by BKBK

    Cached query question

    BreakawayPaul Level 2

      We have a fairly large site that's divided into distinct topics. The site runs off of a single database that contains some page details, like the contact person for that page, along with some other info.


      Since I don't want to query the entire database every time someone hits a page, I use a cached query, and I do one for each topic (since some topics get a lot of traffic, and some get almost none).


      What I have looks something like this:


      <cfset request.qname = request.topicname> (this topic name is set in application.cfc)
      <cfquery name="#request.qname#" datasource="myDSN" cachedwithin="#createtimespan(0,8,0,0)#">
      WHERE topicid = <cfqueryparam value="#request.topic_id#" cfsqltype="cf_sql_numeric"> (this topic ID is set in application.cfc)


      That pulls the info for all pages in the topic and holds it for 8 hrs.  Then for each subsequent page visit in that topic, I have this:


      <cfquery name="details" dbtype="query">
      SELECT ...
      FROM #request.qname#
      WHERE page_name = (current page)


      Now, I've always assumed that if the first query is cached, only the second query will run.  But after wrapping some code around the first one (using cfcache) to see if the cache exists, but so far it looks like it always runs no matter what.  Is this the expected behavior?  I always thought that the cached one is ignored until the cache expires, but maybe I'm not understanding how this works.