View Caching
You can also pass in the caching arguments below and your view will be rendered once and then cached for further renderings. Every ColdBox application has two active cache regions: default and template. All view and event caching renderings go into the template cache.
Argument
Type
Required
Default
Description
cache
boolean
false
false
Cache the view to be rendered
cacheTimeout
numeric
false
(provider default)
The timeout in minutes or whatever the cache provider defines
cacheLastAccessTimeout
numeric
false
(provider default)
The idle timeout in minutes or whatever the cache provider defines
cacheSuffix
string
false
---
Adds a suffix key to the cached key. Used for providing uniqueness to the cacheable entry
1
component name="general"{
2
3
function index(event,rc,prc){
4
5
// call some model for data and put into the request collection
6
prc.myQuery = getInstance('MyService').getData();
7
// view with caching parameters
8
event.setView(
9
view="general/index",
10
cache=true,
11
cacheTimeout=60,
12
cacheLastAccessTimeout=15,
13
cacheSuffix=getfwLocale()
14
);
15
}
16
17
}
Copied!

Purging Views

So now that our views are cached, how do I purge them programmatically? Well, you need to talk to the template cache provider and use the clearing methods:
1
// get a reference to the template cache
2
cache = cachebox.getCache( 'template' );
3
// or via shortcut notation
4
cache = getCache( "template" );
5
// or injection
6
property name="cache" inject="cachebox:template";
Copied!
Then we can perform several operations on views:
  • clearView(string viewSnippet): Used to clear a view from the cache by using a snippet matched according to name + cache suffix.
  • clearMultiView(any viewSnippets): Clear using a list or array of view snippets.
  • clearAllViews([boolean async=true]) : Can clear ALL cached views in one shot and can be run asynchronously.
1
cachebox.getCache( 'template' ).clearView('general/index');
2
cachebox.getCache( 'template' ).clearAllViews(async=true);
3
cachebox.getCache( 'template' ).clearMultiView('general/index','index','home');
Copied!

Disable View Caching

To turn off view caching for your entire application, set the viewCaching setting to false in your config/Coldbox.cfc config file.
1
coldbox = {
2
// Activate view caching
3
viewCaching = false
4
}
Copied!
Last modified 3yr ago
Copy link
Edit on GitHub