I have an application I am moving from BD to lucee. However I am stuck in a giant pitfall. For speed issues I cache many queries so I don't have to go to the database often. But I just can't find a suitable solution here.
Issue 1: The cachedwithin attribute on cfquery tags does not allow for uncaching when I use a #CreateTimeSpan(0, 0, 0, 0)#. I am unable to find a easy way to uncache a specific query.
Issue 2: The filter attribute of <cfobjectcache> does not seem to apply to an action="clear".
However, this forces EVERY query to uncache which is totally unecessary. I would hope/expect for this to work, but it does not
Would appreciate input! To test this just change the first line to a valid datasource.
<cfset yourdatasource = "pwm">
<style> div.ex { border:1px solid black; margin:10px; background-color:yellow; width:500px; } </style>
<cfset selectQuery = "select #RandRange(0,999)# as testColumn">
<cfquery datasource="#yourdatasource#" name="exampleQuery" cachedwithin="#CreateTimeSpan(0, 0, 10, 0)#">#selectQuery#</cfquery>
<div class="ex">Result 1:<cfdump var="#exampleQuery#"></div>
<!--- Result: not cached, it is run for the first time --->
<cfquery datasource="#yourdatasource#" name="exampleQuery" cachedwithin="#CreateTimeSpan(0, 0, 0, 0)#">#selectQuery#</cfquery>
<div class="ex">Result 2:<cfdump var="#exampleQuery#"></div>
<!--- Result: this is a cached query while it should not be --->
<cfquery datasource="#yourdatasource#" name="exampleQuery" cachedwithin="#CreateTimeSpan(0, 0, 0, 0)#">#selectQuery#</cfquery>
<div class="ex">Result 3:<cfdump var="#exampleQuery#"></div>
<!--- Result: this is still a cached query while it should not be --->
<cfquery datasource="#yourdatasource#" name="exampleQuery">#selectQuery#</cfquery>
<div class="ex">Result 4:<cfdump var="#exampleQuery#"></div>
<!--- Result: not a cached query, we did not ask for it to be --->
<cfquery datasource="#yourdatasource#" name="exampleQuery" cachedwithin="#CreateTimeSpan(0, 0, 10, 0)#">#selectQuery#</cfquery>
<div class="ex">Result 5:<cfdump var="#exampleQuery#"></div>
<!--- Result: We would hope for this to NOT BE CACHED. But it is --->
<cfobjectcache action="clear" type="query" filter="exampleQuery">
<div class="ex">Result 6:<cfdump var="#exampleQuery#"></div>
<!--- In theory this would throw an error because we asked for it to be uncached. But filter is not used with action=clear --->
<cfquery datasource="#yourdatasource#" name="exampleQuery" cachedwithin="#CreateTimeSpan(0, 0, 10, 0)#">#selectQuery#</cfquery>
<div class="ex">Result 7:<cfdump var="#exampleQuery#"></div>
<!--- Result: expect this query to not be cached because of the cfobjectcache command above, but the query is still cached --->
<cfobjectcache action="clear" type="query">
<div class="ex">Result 8:<br>Can't show, but the object is cleared. Evidenced by the next query #9 below.</div>
<cfquery datasource="#yourdatasource#" name="exampleQuery" cachedwithin="#CreateTimeSpan(0, 0, 10, 0)#">#selectQuery#</cfquery>
<div class="ex">Result 9:<cfdump var="#exampleQuery#"></div>
<!--- Result: not cached, but no queries are cached, so we have to go back to the database for EVERYTHING again --->