Finishing up a redesign of my favorite video site and I enabled event level caching (finally, I’m able to take advantage of it on this site!!) and I was surprised to find SES variables are not respected when evaluating the cached event.
It is my expectation that ColdBox would consider the RC variables declared within the route when creating the cache key for the event, however, this is not the case. Appending any random URL param busts the cache like one would expect, but, visiting two unique URLs with different values for the SES declared variables does not.
Did I set my expectations higher than I should have, or, is this a bug?
For my case, I’m already doing some onRequestCapture interceptor processing so I’ll just take the CGI.PATH_INFO value and copy it into the URL scope to fix this. But, I wanted to ask the community before sending a pull request since this could change the behavior of your sites.
Actually, I’m thinking this is definitely a bug–but, it may be in our app.
Tracing the code, it looks like the routed structs are considered when building a portion of the cache key. "coldbox.system.cache.util.EventURLFacade.getUniqueHash() (line 48).
I modified /coldbox/system/coldbox.cfc to write the cachekey to disk and a SHA hash of the cached content. You can see the modifications here: https://gist.github.com/1609535
Although ColdBox is using a unique cache-key, the same content is being returned and printed to the screen. Details below…
For anyone wondering what could have caused me to waste a few hours chasing this bug, read on!
Within a service I was using CacheBox to cache the raw data. But, when I created the cache key I failed to hash it.
// This was the bug
var cacheKey = arguments.toString();
// This is the fix
var cacheKey = hash(arguments.toString(),‘sha’);
I assume that only the first X characters were used to set/lookup the item in the cache either by CacheBox or ColdFusion9. It just happened that this page, the arguments are almost the same with the unique portion found near the end of the string.
Even deeper, I was caching queries with CacheBox and I used the SQL to create the cache-key, but, failed to realize that the values were not in the SQL. They are all added as queryparams. DOE!
Enjoy your weekend peeps! It’s been a loooooong week for me