Modifying Query cache

Finally making the switch from railo to Lucee. So far so good. Except for one behavior. When I cached a query I could access the query object in the cache and modify it. With lucee it seems to give me a set the cache and return a clone of what was cached during the query. For example:

<cfquery name = "myQuery" result = "result" cachedWithin = "1day">
SELECT data,' ' AS formattedData
FROM table
</cfquery>

<cfif NOT result.Cached>
<cfset myQuery.formattedData = myquery.data *2>
</cfif>

<!-----IF cached formattedData is empty----->
<cfreturn myQuery>

@kpetrow Hi and welcome to Lucee. The change I believe you are talking about was made to dramatically improve performance in Lucee. Railo (and early versions of Lucee) used to duplicate the cache every time so local changes wouldn’t be persisted in the cached version but this caused a considerable amount of overhead for large queries. I put in the ticket to change the behavior because I had a client whose entire site would go down due to the fact that cloning a query was single threaded!!

https://luceeserver.atlassian.net/browse/LDEV-1366

This led to absolutely horrible performance on my client’s app since every single web request cloned the same query and it basically single threaded their entire web app.

Micha changed queries to not be duplicated so if a user wanted to modify the query, it was up to them to duplicate it on their own. I think he also tried to put in some logic that would detect if you changed a query and would then duplicated it on the fly for you, but I’m not sure I ever tested that.

I’m not completely sure what your example is doing above but it seems you’re trying to obtain a query that may be cached and modify it on the fly before returning it? If that is the case, your changes inside the if statement would never be reflected inside the cached version of the query. But, based on how Railo/Lucee used to work, I think that would have always been the case since it always used to duplicate int he past so I’m not entire sure what you’re saying changed from your perspective.

Thanks for the quick reply. Is there a method to altering the cache directly? I am trying to alter the cached query.

Maybe something like this:

<cfquery name = "myQuery" result = "result" cachedWithin = "1day">
SELECT data,' ' AS formattedData
FROM table
</cfquery>

<cfif NOT result.Cached>
<!--- here i use some session variables( timezone etc) that is not available in the initial SQL query---->
<cfset setCache(myQuery.formattedData, myquery.data * 2)>
</cfif>


<cfreturn myQuery>

Karl

I’m not aware of any method to alter a query in the cache. From what I’ve seen, Lucee works hard to prevent one thread from being able to change what’s in the cache so it doesn’t affect other threads. I guess your use case isn’t accounted for.

It’s more work, but you could manually handle the caching with cacheGet() and cachePut(), you’d just have to duplicate the work of creating unique cache keys and not overfilling the cache, etc.

thanks so much for the help. I didnt see cachePut(). Have a great day!