Blog

Tip of the Week: View Caching

Brad Wood July 10, 2012

Spread the word

Brad Wood

July 10, 2012

Spread the word


Share your thoughts

Do you have slow views whose output rarely or never changes? You can get an easy boost in performance by caching those views so they are not re-rendered on every request.

The following code shows two ways to cache the output from a view for a given number of minutes:
event.setView(name='home',cache=true,cacheTimeout=30);
#renderView(view='tags/footer',cache=true,cacheTimeout="60")#

Do you have dynamic portions of your view, or use a multilingual site? Use a cache suffix so ColdBox can cache each version of the view and always serve up the correct one.
event.setView(name='home',cache=true,cacheTimeout=30,cacheSuffix=rc.language);

Like control? The cacheTimeout sets how long the view is allowed to live in cache before it is expired. You can also set a cacheLastAccessTimeout to kick it out of the cache sooner if no one hits it within a given time frame. The following view will be cached for 2 hours, but will be evicted from the cache sooner if no one hits it for 20 minutes.
event.setView(name='contactUs', cache='true',cacheTimeout="120",cacheLastAccessTimeout="20");

P.S. To programmatically clear out a cached view on command use the following:
cachebox.getCache('template').clearView('general/index');

More info here: http://wiki.coldbox.org/wiki/Layouts-Views.cfm#View_Caching
 

Add Your Comment

Recent Entries

Into the Box 2024: Your Gateway to the Future of Tech!

Into the Box 2024: Your Gateway to the Future of Tech!

Are you ready to advance your coding skills? The future of Modern Web Development awaits at Into the Box 2024, and we're thrilled to announce that due to high demand, we're extending our Early Bird pricing for an additional week!

Maria Jose Herrera
Maria Jose Herrera
April 26, 2024
Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Unfortunately, we often hear this message from clients who thought it would never happen to them... until it did. Some believed they could delay the expense of Implementing ColdFusion security best practices for one year, while others were tempted to put it off for just a few months. However, in today's rapidly evolving digital landscape, the security of web applications, including ColdFusio...

Cristobal Escobar
Cristobal Escobar
April 16, 2024
Ortus March Newsletter

Ortus March Newsletter

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
April 01, 2024