title: Resetting cached query with cachedwithin
body: <p>Inside a <code>cffunction</code> I have a query that I want to long cache by setting the <code>cachedwitin</code> to a big value.  However, I also want to clear that cache under a few circumstances.</p>
  
  <p>I've done this in a number of places, but in one of them the cache is never updated and I always get the original value if I ask it to give me the cached value.</p>
  
  <p>The <a href="http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7fae.html" rel="nofollow">cfquery documentation</a> states:</p>
  
  <blockquote>
    <p>To use cached data, the current query must use the same SQL statement, data source, query name, user name, and password.</p>
  </blockquote>
  
  <p>This is the case with the query, since it's a single sql statement with no non-sql except the <code>cfqueryparam</code>; datasource and query name don't change and username and password are not specified.</p>
  
  <p>The relevant code is:</p>
  
  <pre><code>&lt;!--- Long cache the query since the values rarely change, but allow the cache to be cleared. ---&gt;
  &lt;cfif Arguments.ClearCache EQ false&gt;
      &lt;cfset local.CachedWithin = CreateTimeSpan(7,0,0,0)&gt;
  &lt;cfelse&gt;
      &lt;cfset local.CachedWithin = CreateTimeSpan(0,0,0,-1)&gt;
  &lt;/cfif&gt;
  
  &lt;cfquery name="local.qryName" datasource="#Variables.DSN#" cachedwithin="#local.CachedWithin#"&gt;
      SELECT
          [User].[Name]
      FROM
          [User]
      WHERE
          [User].[UserID] = &lt;cfqueryparam value="#Arguments.UserID#" cfsqltype="cf_sql_integer"&gt;
  &lt;/cfquery&gt;
  </code></pre>
  
  <p>Why does this work in other places, but not here?</p>