Blog

Brad Wood

May 23, 2013

Spread the word


Share your thoughts

An important piece of a well-performing application that can scale under load is caching.  This can (and should) be implemented at multiple levels.  CacheBox is an enterprise cache API and aggregator that can be used stand-alone and comes bundled with the ColdBox framework.  ColdBox has some nice hooks to allow you to utilize CacheBox in several ways with very little work and Event Caching is one of those ways.

Event Caching gives you the ability to cache the result of any event in your application so that subsequent requests will bypass all the processing in your handlers, views, and layouts, and immediately return the cached response.  This is great for APIs or sites with data that is accessed more than it is modified, or if the data being displayed doesn't need to be up-to-the-second fresh.  

Here's some things to consider about Event Caching:

  • It is easily activated by toggling a setting and then adding cache=true to the actions you want cached in your handler.
  • A different item will be created in the cache for each unique permutation of values in the request collection.
  • You can control how long the event is cached in minutes with cacheTimeout=30.
  • All handler processing is skipped, so you won't want to cache events that need to save to the database or modify the state of the application
  • PreProcess/PostProcess interceptors and requestStart/requestEnd events will still run even if the event is cached

Let's look at how easy Event Caching is to start using.  First, you'll need to enable Event Caching in your config like so:

coldbox.eventCaching = true;

Next, set cache=true in the method declaration of the action you want to cache in your handler.  cacheTimeout is an optional parameter to control how long the event is cached.  cacheLastAccessTimeout is an optional parameter that will cause the entry to be cleared from the cache sooner if it isn't being used.

function showEntry(event,rc,prc) cache="true" cacheTimeout="30" cacheLastAccessTimeout="15"{
    //get Entry
    prc.entry = getEntryService().getEntry(event.getValue('entryID',0));
        
    //set view
    event.setView('blog/showEntry');
}

Since entryID is stored in the request collection, there will be a different cached response for every entryID that the site is access with.  Keep in mind the maximum number of items which can be stored in your "template" cache.  Furthermore, if your site employs things such as localization, you might want to ensure that a version of the event gets cached for each language.  Setting getFWLocale() into the rc in an onRequestCapture interceptor is an excellent way to ensure caching takes the user's language into account.

More info here: http://wiki.coldbox.org/wiki/EventHandlers.cfm#Event_Caching

P.S. What do you do if your data changes, but the event is still cached?  You can programatically expire events from the cache by grabbing the "template" cache and using the clearEvent(), clearEventMulti(), or clearAllEvents() convenience methods.

cachebox.getCache("template").clearAllEvents();

Add Your Comment

Recent Entries

CommandBox: A Smarter Foundation for BoxLang and CFML Workflows

CommandBox: A Smarter Foundation for BoxLang and CFML Workflows

In day-to-day development, some tools simply do their job… and others quietly change the way you work. CommandBox falls into the second category.

It doesn’t replace your editor, framework, or existing applications. Instead, it becomes the common ground where CFML and BoxLang development meet ,giving teams a consistent, reliable way to build, run, and evolve their projects.

Victor Campos
Victor Campos
January 16, 2026
BoxLang v1.9.0 : Production-Ready Stability, Enhanced Lifecycle Management, and Rock-Solid Reliability

BoxLang v1.9.0 : Production-Ready Stability, Enhanced Lifecycle Management, and Rock-Solid Reliability

Happy New Year! The BoxLang team is excited to announce BoxLang 1.9.0, a significant stability and compatibility release focused on production-readiness thanks to our client migrations and new application deployments. This release also introduces array-based form field parsing conventions, enhanced datasource lifecycle management, improved context handling, and resolves over 50 critical bugs to ensure enterprise-grade reliability for mission-critical applications.

Luis Majano
Luis Majano
January 09, 2026
DocBox v5 - Reborn: Modern API Docs for BoxLang & CFML

DocBox v5 - Reborn: Modern API Docs for BoxLang & CFML

Welcome to DocBox v5! We didn't just update DocBox. We rebuilt it from the ground up.

DocBox v5.0.0 represents a complete architectural rewrite—modern syntax, blazing performance, and a stunning new look that finally brings API documentation into 2025. Gone are the clunky HTML pages of yesteryear. Say hello to a gorgeous, theme-driven single-page application that makes browsing your API docs feel like using a premium developer tool. We have also released a dedicated module for BoxLang: BX-DOCBOX. A fully interactive CLI tool for generating your docs from the command line using pure BoxLang.

Luis Majano
Luis Majano
January 06, 2026