[Coldbox 6.4] Event Caching and Ignoring RC Scope?

First of all, Coldbox event caching is awesome. The ability to cache the output of an entire event can make a Coldbox app extremely fast. However, one caveat/tradeoff of event caching is that Coldbox uses the rc scope to determine the cache key, instead of the event name. This gives users the flexibility to create different event caches for pages like:

/blog/?postId=1
/blog/?postId=2

While this is beneficial for pages that utilize rc scope to display different output, it does make it difficult to cache pages if you do not want the rc scope to influence whether a cached copy of an event should be returned or not.

For example, let’s say you cache the home page of your app to make sure it loads extremely fast. You may not be able to control whether site visitors access the home page through a “pure” URL with no parameters. If the visitor arrived by clicking a link from an email marketing campaign, there might be a series of tracking variables like ?utm_source appended to the URL. Depending on the situation, you could have every site visitor create a new cached copy of the event. Additionally, a malicious user could hit a page with an infinite number of URL variables which would create new cached instances of the output on every request.

Is there a way to tell Coldbox to cache an event and ignore the rc scope? If not, this might be a valuable feature, especially for static pages like a home page or marketing landing pages.

At this point it does not. It always looks for the rc context hash to incorporate it for unique cacheable items. This is done by the EventURLFacade object called from the request service. The tricky thing, is that even if you turn it off, you might want it ON for other events. So maybe if this was a feature request, it would have to be at the event action level via another metadata annotation. Right now we have the following available annotations:

  • cache - Turn on or off
  • cacheTimeout
  • cacheLastAccessTimeout
  • cacheProvider - which provider to use, default to template

We could add something like:

  • cacheIgnoreRC : Defaults to false

Then only if that is set to true, will it ignore it. However, we then need to modify request services, url facades and then create tests cases for those :slight_smile:

If you are willing to take this on with me. We can do it!

Sure thing! I think it would be a great addition to Coldbox. I’m fairly confident I can handle adding the metadata annotation and request service changes. However, I will probably need some help from the Chuck Norris of TestBox in order to write the right unit tests for it.

Here are some pointers.

Here are some standalone suites I use to test specific scenarios

Event Caching Suite:

1 Like

Thank you for the links to the tests! I’ll set aside some time this weekend to start playing with it.

This ticket might be relevant for a more general discussion: [COLDBOX-847] Coldbox Template Caching for the Future - Welcome