Template caching – or more accurately, view caching – is done within render/setView, for example setView(cache=true,cacheTimeout=90,cacheSuffix=”user_#session.userID#”).
So view caching can have “user” specific caching – if you use the cacheSuffix attribute. But you have to add that everywhere you use set/renderView, otherwise everyone sees the same cached views.
Event caching - caches the entire event and doesn’t have any options for a prefix (again, by default everyone sees the same cache) – but that’s where the onRequestCapture interception point comes in. The cache “key” for event caching is basically the handler/event name and the requestCollection serialized and then hashed – to create a unique cache “key” (I think it’s something like cbox_incomingContextHash = hash(rc.toString()) in coldbox.web.services.RequestContext). You need to use onRequestCapture (which fires before the cache is inspected) to inject values that can potentially alter the serialized/hash key.
I use a combination of event and view caching – depending on the requirements needed.
The good thing about view caching, is that you can set the timeout to be different than the standard cacheBox timeout you’ve set, and you can, as described earlier, alter the prefix to fine tune the caching properties of individual views.
Let’s say you want everything cached in your application for 15 minutes, and for everything to be based on a user’s loginID:
1.) Turn on event caching in Coldbox.cfc
2.) Cache the events in question in your handlers ().
3.) Add an interceptor (say cacheControl.cfc) and add the onRequestCapture function. Add the user ID into the rc (rc.userID = session.userID)
4.) Reinit you app.
5.) bam! You have a site-wide user-specific cache
What’s more, if you set session.userID = 0 in onSessionStart, “public” users would all see the same cache before they logged in. Pretty cool.
Elsewhere in your site you may have a few views that aren’t “user” specific (why create lots of cached copies of the same thing!)?, and in those cases you may want a longer cache timeout (say 2 hours) and with no prefix. That’s where the render/setView cache comes in.
All of the examples above are obviously just quickly hacked together to demonstrate, but hopefully you get the idea
Hope that helps