Copy link to clipboard
Copied
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
</cfquery>
<cfreturn getAllRecords>
</cffunction>
<cffunction name = "add" .....>
insert logic
</cffunction>
</component>
Then I am invoking this component on a page which has two includes and other business logic.
index.cfm
<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
</cfquery>
<cfset addStudent = o_student.add(......)>
</cfif>
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.
Thanks.
Copy link to clipboard
Copied
Instead of caching the query, set it to a session variable when you invoke your cfc.