1 Reply Latest reply on May 27, 2009 12:33 PM by Dan Bracuk

    cfquery cachedwithin issue

    funandlearning333 Level 1

      Hi All,


      I am facing an issue with the cachedwithin attribute of cfquery. Currently I am using a query like below in cffunction defined within a cfcomponent


      <cfcomponent name="courses>


        <cffunction name="getRecords" access="public" .....>


             <cfquery name="getAllRecords" datasource="msee" cachedWithin="#createTimeSpan(0,2,0,0)#">


              select * from students     


            <cfreturn getAllRecords>


      <cffunction name = "add" .....>


                 insert logic


      Then I am invoking this component on a page which has two includes and other business logic.




      <cfset o_student = createObject("component", "courses")>


      <cfset q_student = o_student.getRecords()>




      I have two include files. One include files lists all the students (which loops over q_student variable), and other include file has a data entry form which adds a new student.


      So when I add a new student, I am reusing the query defined in the component above as follows:


      <cfif action is "add">


            <cfquery name="getAllRecords" datasource="msee" cachedWithin="#createTimeSpan(0,0,0,-1)#">


              select * from students     




            <cfset addStudent = o_student.add(......)>




      And once the add function is performed and the page is refreshed, I do not see any updated records of the students, the debug info shows two queries with the same number of records and one query is a cached query,


      Can anyone suggest if what I am doing is right? If its not, what are the other ways to update the cache...I do not want to use <cfobjectcache>, I just want to refresh only one query.