In my ColdBox CMS I use a catch-all route for pages like this:
route( ":slug" ).valuePairTranslation( false ).to( "pages.show" );
My Page entities use a parent/child hierarchy so pages can be nested underneath other pages like this:
/california/ ← California page
/california/irvine/ ← Irvine page child of California
If you’re using Coldbox’s event caching functionality, things can get a little tricky because Coldbox will only look at the first path segment when populating the rc scope from the route.
So, for example, if I type in the following URL:
/california/ the rc.slug value will be california.
/california/irvine/ the rc.slug value will still be california.
All other things in the rc being equal, the event cache hash will see the same rc.slug value for both the parent and child URLs. This is bad because it means that a cached response could return the wrong page back to to the user.
How do we fix this? Simple.
There’s a Coldbox interceptor method called onRequestCapture() which you can use to help influence the cache keys to ensure your parent/child pages get treated as unique pages and not lumped together.
Here’s how you might do it:
// registered interceptor app.cfc
/**
* onRequestCapture
* This event is called at the very beginning of the request processing
* we can use it to influence cache keys, etc...
*
* @event
* @data
* @buffer
* @rc
* @prc
*/
function onRequestCapture( event, data, buffer, rc, prc ){
rc[ "pathSegments" ] = event.getCurrentRoutedUrl();
}
The above code will execute before the event cache hash is calculated and ensures the rc scope accounts for the full routed URL and not just the first path segment.
I should also point out, if you’re using Coldbox 8, you have a lot of new features available to you to personalize event caching. You can see the details here: Event Caching | ColdBox HMVC Documentation