Flush Object Cache

I have a question on how to use the redis object cache.

I recently switched from internal caching in Lucee and added the Redis Extension. I also have enabled the object cache.

I want to use the cache to display certain items and to deliver it fast, it should come out of the cache.
From time to time I need to refresh it, so I introduced a URL param flushCache=1.
If I detect it, I want to empty the cache, but as this is during the request, the cache should be populated again, as the code needs to be executed.

So, here’s my code:

    <cfif isDefined("url.flushCache") && url.flushCache eq "1">
      <cfcache action="flush" key="#cacheName#" />
    <cfcache action="cache" timespan="#defaultCachingTime#" key="#cacheName#">
      <!--- do stuff that should be then stored into the cache --->

Unfortunately, the page request, when I do it will be super fast, as it seems that Lucee will still give me the content from the cache, and flush it afterwards.
Next time I hit the page (even without the URL param), cache is empty and processing takes very long.

What am I doing wrong?

Hey @fritz ,
According to Adobe Coldfusion’s documentation for the <cfcache action="flush"> command:

flush: remove the current versions of cached pages, fragments, or an object from the cache. The cache is refreshed the next time a user accesses the item. For more information see Description.

I think this means that the cached object is not flushed until the end of the request.


It’s worth mentioning the Lucee behavior may differ from Adobe. And specifically, the Ortus Redis extension may have it’s own behaviors. The question may be whether Redis processes it right way or not. I know for certain Couchbase’s flush’s are async and can take a while. I can confirm the Redis API method we’re hitting alter today.

@fritz Looking at Lucee’s cache interface (which Ortus implemented in our Redis extension), there is no flush() method. When the cfcache tag receives a request to flush a specific key, Lucee calls the cacheRemove() BIF under the hood which calls the cache implementation’s remove(String key) method. The Ortus Redis extension (which I assume you’re using here since you tagged the post as such) then deletes the key using this SDK method.


The Jedis docs don’t really clarify if the operation is synchronous or asynchronous. I don’t see any code in Lucee that indicates the flush is async. My guess is you’re not doing anything wrong per se, but you’re making the assumption that Redis operates synchronously and it likely operates async like I know Couchbase does by default.

@lmajano may be able to shed some additional light here since he authored the Redis extension and is more familiar with it.

I am not sure I can add much more. It would be worth asking also to the lucee list on whether this is done at the end of the request or immediately.

However, our interface basically implements whats been given. I have also revised the Jedis source and the calls to those commands are sync and the del redis command is also sync: DEL – Redis

So at this point, I would say open a ticket with lucee as well. Also, have you tested the same code but using a local cache?

1 Like

I can say with 95% certainty based on my review of the Lucee source code that the <cfcache action="flush"...> tag is executed immediately and not at the end of the request. The code is all inline and there is no threading. I’m pretty certain this is just a delay on the Redis side of things. Putting in a

sleep( 3000 )

would probably help prove that.

Hi all,
thanks for all of the exhaustive answers! I will try and experiment with your suggestions!


1 Like