Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new handler metadata property cacheIncludeRcKeys #503

Open
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

homestar9
Copy link
Contributor

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:

  1. A malicious attacker could take advantage and create an unlimited number of cache entries for the same page simply by adding a random URL variable.
  2. Marketing efforts often require appending a unique tracking variable to a URL (e.g. 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 of RC keys to include when generating a cache key. All keys not in the list are ignored. To maintain backward compatibility, the default value for cacheIncludeRcKeys is * which considers all keys.

How Does it Work?
Simply include a new metadata attribute cacheIncludeRcKeys to a handler and specify a list of RC keys you want to be included in the cache key generation process. Here are some examples:

function show( event, rc, prc ) cache="true" cacheTimeout="10" cacheIncludeRcKeys="slug" {
  ...
}

The above code will ignore all RC keys except for slug when generating a cache key. So, if you had a route pages/:slug resolve to pages.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:

function show( event, rc, prc ) cache="true" cacheTimeout="10" cacheIncludeRcKeys="slug,id" {
  ...
}

@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. :)

homestar9 and others added 2 commits September 21, 2021 08:59
This new metadata option gives developers more control over which RC scope variables are considered when generating the cachekey
@bdw429s
Copy link
Contributor

bdw429s commented Sep 21, 2021

This pull request has been mentioned on Ortus Solutions Community. There might be relevant details there:

https://community.ortussolutions.com/t/coldbox-6-4-event-caching-and-ignoring-rc-scope/8886/11

@homestar9
Copy link
Contributor Author

@lmajano Let me know if you have any questions or need anything else from me? I'm curious to hear your feedback on the PR and tests.

@jclausen
Copy link
Contributor

This also relates to https://ortussolutions.atlassian.net/browse/COLDBOX-1203

@lmajano I would recommend merging this one in and then we can address 1203

@homestar9 homestar9 closed this Feb 29, 2024
@homestar9 homestar9 reopened this Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants