How does it work ? I tried simple query in java and same
coldfusion on postgresql without any load. Java gives me
results, about 280ms on query and 200ms on processing
cf on the other side gave me times about 1500ms, 900ms,
- query cache was set to 0, no arguments in cfquery related
was not used, just name, datasource. 200ms is under time
database to process request, so seems to me that cf simply
Can anyone help me to understand how cf works in this case ?
query caching is quite agressive technique that little scares
I coded a simple example:
<cfquery name="test" datasource="cfdocexamples"
select e1.*,e2.* from employees e1,employees e2
It runs in about 25 ms on average.
I then add the attribute
'cachedwithin="#CreateTimeSpan(0,1,0,0)#" '. It takes about 40ms on
the first run. Each additional call takes 0ms. Here is the test
output of the query object itself (not the data):
EXECUTIONTIME 0 RECORDCOUNT 225
SQL select e1.*,e2.* from employees e1,employees e2
The query takes no time to run, since the data is cached.
This is great for static information, like the classic STATES
query. It is also great for code that will not change too
frequently, like the page tree of your site. You can always clear a
query by setting its cachedwithin to 0. Then re-cache the query. Or
just let the cache expire. Your choice.
I do not believe that CFMX lied about your resulttimes. 250ms
is a reasonable query time. My example was run against msaccess and
took ~25ms. You can test for yourself by wrapping your query with a
getTickCount before and after the query. Then subtract the first
value from the second. It will match what the debugging says, I am
A great place to start is always the cf documentation (
livedocs). The reference
guide gives you brief descriptions of the cfquery tag and its
attributes. Searching the docs on cachedwithin yields
page. It has a good description and example of caching.