Blog

Luis Majano

January 27, 2015

Spread the word


Share your thoughts

In ColdBox 4 we have expanded the runEvent() method to allow you to add caching parameters so ColdBox can take care of caching output from events.  This is a great way to accelerate the execution of widgets or viewlets within an application as it will execute them and cache them as needed.  Here is the new signature for the runEvent() method.

/**
* Executes events with full life-cycle methods and returns the event results if any were returned.
* @event The event string to execute, if nothing is passed we will execute the application's default event.
* @prePostExempt If true, pre/post handlers will not be fired. Defaults to false
* @private Execute a private event if set, else defaults to public events
* @defaultEvent The flag that let's this service now if it is the default event running or not. USED BY THE FRAMEWORK ONLY
* @eventArguments A collection of arguments to passthrough to the calling event handler method
* @cache.hint Cached the output of the runnable execution, defaults to false. A unique key will be created according to event string + arguments.
* @cacheTimeout.hint The time in minutes to cache the results
* @cacheLastAccessTimeout.hint The time in minutes the results will be removed from cache if idle or requested
* @cacheSuffix.hint The suffix to add into the cache entry for this event rendering
* @cacheProvider.hint The provider to cache this event rendering in, defaults to 'template'
*/
function runEvent(
    event="",
    boolean prePostExempt=false,
    boolean private=false,
    boolean defaultEvent=false,
    struct eventArguments={},
    boolean cache=false,
    cacheTimeout="",
    cacheLastAccessTimeout="",
    cacheSuffix="",
    cacheProvider="template"
){

Here are the arguments of interest for caching:

  • cache : activate caching
  • cacheTimeout : the default timeout of the entry
  • cacheLastAccessTimeout : the idle timeout of the entry
  • cacheSuffix : A string suffix to incorporate into the cache key for uniqueness
  • cacheProvider : The CacheBox region

The cache argument tells ColdBox to activate caching for the output of the event execution. It will execute the event with the passed in parameters and then cache the output of such execution (if any, if none then it does not cache anything). It will create a cache key composed of the event name, the cacheSuffix and the eventArguments structure. So please be aware of this so you don't have key collisions. By default, all cacheable entries will be stored in the template cache region of CacheBox and you can use many different cache methods to purge this area (See API Docs):

  • clearAllEvents([any async])
  • clearEvent(any eventsnippet, [any queryString])
  • clearEventMulti(any eventsnippets, [any queryString])

Here are some examples


#runEvent( event="widgets.users", cache=true )#


#runEvent( event="widgets.users", cache=true, cacheTimeout=60 )#


#runEvent( event="widgets.users", eventArguments={ filter:true }, cache=true, cacheTimeout=60 )#

Happy Caching!

Recent Entries

Into the Box 2024 Last Early Bird Days!

Into the Box 2024 Last Early Bird Days!

Time is ticking, with less than 60 days remaining until the excitement of Into the Box 2024 unfolds! Don't let this golden opportunity slip away; our exclusive Early Bird Pricing is here for a limited time only, available until March 31st. Why wait? Secure your seat now and take advantage of this steal!

Maria Jose Herrera
Maria Jose Herrera
March 20, 2024
Ortus February Newsletter 2024

Ortus February Newsletter 2024

Welcome to Ortus Solutions’ monthly roundup, where we're thrilled to showcase cutting-edge advancements, product updates, and exciting events! Join us as we delve into the latest innovations shaping the future of technology.

Maria Jose Herrera
Maria Jose Herrera
March 06, 2024
Unveiling the Future of CFML Development - 3rd Round of Sessions

Unveiling the Future of CFML Development - 3rd Round of Sessions

Welcome back to our journey into the future of CFML development! As excitement continues to build for Into the Box 2024, we're thrilled to bring you the latest updates on what promises to be a transformative event. Continuing our blog post series, let's delve deeper into the third wave of session releases and discover the key surprises awaiting attendees. Learn More

Maria Jose Herrera
Maria Jose Herrera
March 01, 2024