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);
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