Added new handler metadata property cacheIncludeRcKeys
#503
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request is in response to this discussion in the Coldbox community.
This new feature for Coldbox gives developers more flexibility with event caching and different RC scopes. The end result should be more efficient caching and improved page load speed for many users.
The Problem:
Currently, event caching considers the entire
RC
scope when generating a cache key. This means that changing any URL or FORM variable on a request will force Coldbox to generate a new cache entry. This behavior is problematic for a few reasons:utm_source
). In this type of scenario, there is no need to create a new cached event for every unique URL.The Solution
I was inspired by Wirebox's populator include/exclude arguments which lets developers specify a list of keys to consider when populating an entity. My idea was to create a new metadata property called
cacheIncludeRcKeys
which would allow specifying a list ofRC
keys to include when generating a cache key. All keys not in the list are ignored. To maintain backward compatibility, the default value forcacheIncludeRcKeys
is*
which considers all keys.How Does it Work?
Simply include a new metadata attribute
cacheIncludeRcKeys
to a handler and specify a list ofRC
keys you want to be included in the cache key generation process. Here are some examples:The above code will ignore all
RC
keys except forslug
when generating a cache key. So, if you had a routepages/:slug
resolve topages.show
, the following URLs would all utilize the same cache key:https://mysite.com/pages/foo
https://mysite.com/pages/foo?utm_source=google
https://mysite.com/pages/foo?utm_source=bing
You can also include multiple
RC
keys by specifying a list in the metadata attribute like this:@lmajano I know you are probably busy with preparations for Into The Box so no need to rush on this one. I'll be attending the conference in person if you would like to chat about this PR. Looking forward to catching up with you and the entire Ortus team. :)