[thesite] query results caching

jeff jeff at members.evolt.org
Mon Mar 5 11:52:59 CST 2001


: From: rudy
: > In ColdFusion you can do this by stuffing
: > query results into an structured application
: > variable.
: why would you not use query results caching?

sometimes it's more appropriate to store the results of a query in a much
long-term mechanism.  query caching can do this, but it's not nearly as
controllable as say an application scoped variable.  rather than let the
cold fusion server handle caching of the query (and possibly allowing the
query to run again when i don't want it to), i can simply store the results
of the query in an application scoped variable and know that query will
*not* run again until the server is rebooted or i explicitly tell it to run
again by resetting that application variable.

there's also the likelihood that you may not have the choice of using query
results caching because it's been disabled.

: it's a cold fusion feature, so why would you
: go to all the trouble of saving stuff in
: structures?

it's not really that much trouble.  take these two as an example.  the first
one is using query results caching.  the second is storing the query in an
application scoped variable.

example #1

<cfquery name="gettangoandcash" datasource="#data#"
  FROM movies
  WHERE dialogue LIKE '%fubar%'

example #2

<cflock timeout="30" throwontimeout="no"
  type="exclusive" scope="application">
  <cfparam name="application.gettangoandcash" default="">
  <cfif NOT IsQuery(application.gettangoandcash)>
      SELECT id
      FROM movies
      WHERE dialogue LIKE '%fubar%'

you'll notice that there are a few more lines to the second example.
however, for the most part these lines (<cflock>, <cfparam> with a minor
change to the name the query will be stored as, and <cfif NOT IsQuery()>
with a minor change to the name the query will be searched for by) can be
copy-n-pasted for future uses.

: the query results are a structure already,
: right?

well, yes sort of.  they're a structure the same way a normal query is.
whether they're cached or scoped to an application or session variable is
irrelevant -- the results are accessed in the same fashion.

does this make more sense?


mailto:jeff at members.evolt.org

More information about the thesite mailing list