I work a lot with Varnish and many clients have expressed a desire to have some pages pretty much never expire and other pages expire as quickly as every minute. The idea behind this module is that it provides three main features for controlling the cache-control header:
- A secondary cache length that can be used for a list of exception paths.
- A list of paths that should be excluded from caching by setting the cache control header to no-cache.
- Allow cache-control headers for 301 and 302 redirects using drupal_goto to have individual cache lengths set.
The module also includes rules integration and manipulates the core performance page a bit so users can find the module's configuration page. Overall it's a fairly simple module that just manipulates the cache-control header based on path, and possibly more complex options with Rules.
I am aware there is a context module that allows header manipulation, but this module is intended to be a lightweight solution for all cache-control handling that isn't dependent on other modules.
https://drupal.org/sandbox/steel-track/2280899
git clone --branch 7.x-1.x http://git.drupal.org/sandbox/steel-track/2280899.git
Comments
Comment #1
skh commentedA few quick ones:
Nothing that's really release blocking, but there's some notes. I use varnish a lot too so am interested in this module, I like the idea.
Comment #2
skh commentedComment #3
Taz commentedI second point 3, allowing cache-control headers in drupal_goto. In a high traffic environment that may have a lot of 'legacy redirects' that can't be deeper in Apache, it's good to have cacheability on 301's at least coming from Drupal.
Comment #4
steel-track commentedAll changes have been made as requested. The long lines caught from the code sniffer are straight out of the block module so I am going to leave them alone. Same with the $_GET['q'] references.
Comment #5
steel-track commentedComment #6
steel-track commentedI missed where skh said he didn't see any blockers, just had notes.
@skh Thanks for the review!
Setting this to reviewed by the community. Let me know if that isn't correct.
Comment #7
MattWithoos commentedHi, thanks for your contribution.
Best practice mandates that you should not use raw $_GET or $_POST in modules. Use the Drupal API, read more here:
https://api.drupal.org/api/drupal/includes!common.inc/function/drupal_ge...
Additionally it is poor practice for the Project Applicant to set RTBC themselves, for reasons I'm sure you can imagine. That aside, the RTBC status is set only after a thorough review and test has been conducted by one or more experienced developers and they or another experienced developer have deemed it ready to be RTBC. User "skh" provided only a "quick" review and unfortunately hasn't followed up.
It looks like this module is being ignored, sadly, and I suspect it's because only people with very specific setups will be able to test it. Is it possible for you to set up a server environment with a base Drupal install, and allow a git admin / Drupal reviewer to install the module and test it? Only suggesting this as it may help your project move along.
Cheers
Matt
Comment #8
steel-track commented@matt-withoos Thanks for the great feedback!
As far as testing is concerned, the only item that needs to be correct is the cache expiration header that gets set. Whatever Varnish or another proxy in front of it does with that is up to that component in the infrastructure. I am therefore writing automated tests for the module to check the header given different configurations and conditions.
I will update this thread once that work is completed and pushed.
Also, the $_GET stuff is straight out of the block module's implementation of how they do path parsing. I can convert to drupal_get_query_parameters but I would prefer to stay close to the block implementation.
Comment #9
MattWithoos commentedRight, then that looks fine.
I would suggest doing 3 reviews of other modules (as it looks like you've got a good grasp on development) and then we can get "PAReview: Review Bonus" on this module, meaning it will get some attention from Drupal admins + better developers than I, hopefully who will move it past RTBC or provide some good feedback.
Comment #10
stefank commentedHi,
Automated Review
there are still some outstanding errors.
http://pareview.sh/pareview/httpgitdrupalorgsandboxsteel-track2280899git
Manual review
README.txt/README.md
(*) No: Follows the guidelines for in-project documentation and the README Template.
hook_help() is missing in your module.
Great job so far.
Comment #11
samir_mankar commentedAutomated Reviews
The Coder Sniffer has found some issues with your code (please check the Drupal coding standards).
Manual Reviews
The README.txt file do not follow the guidelines for in-project documentation. Pleas check the README.txt Template for the guidlines.
Comment #12
devd commentedHi Trak,
Update your project git path on your created issue by the following.
git clone --branch 7.x-1.x http://git.drupal.org/sandbox/steel-track/2280899.git
Comment #13
samir_mankar commentedComment #14
steel-track commentedComment #15
steel-track commentedI am now working on automated tests for the module, but I have addressed all reported issues in this thread and am setting to needs review as automated tests are not a requirement.
Comment #16
steel-track commentedAutomated tests are now included with the module that check the Cache-Control header given a set of configurations.
Comment #17
adammaloneI'd be happy to RTBC this if the following are either addressed or have a mitigation.
2 minor nits
ape_page_delivery_callback_alter does not check on the status of the response.
Curling both a 404 response and a 403 response as an anonymous user gave a response of
Cache-Control: public, max-age=60I'm not sure whether this is the desired intention although at the same time agree that most reverse proxy accelerator solutions (looking at you Varnish) will be configured to:
With this in mind I was looking to see whether this was a known response that you had an understanding of and perhaps could add to the README so users were aware that it came with 403/404 caching too and that it was the responsibility of their reverse proxy to deal with that.
301/302 redirects aren't being cached.
The reason for this is because a drupal_goto() never makes its way through drupal_deliver_page() - this is pretty logical as we're just delivering a header() and telling the browser to look under another rock. Because drupal_deliver_page() doesn't get executed during the redirect step, the ape_page_delivery_callback_alter() function never gets called. This is what sets the header for reverse proxies and if it doesn't get called, the headers won't get added.
By altering ape_drupal_goto_alter() to the following, those headers get set and the reverse proxy will see them in their shining glory.
Comment #18
steel-track commented@typhonius: Thank you for the awesome feedback.
1. Visibility is declared now for testApeHeaders().
2. Added configure line to .info file.
3. Added in checks for 404 and 403. 404 cache lifetime is now a configurable parameter and 403 sets cache age to 0.
4. In regards to your question about respecting sessions, that logic is in ape_check_cacheable() where I check if the user is anonymous, if caching is enabled and if the path is in the current list of exclusions.
5. Added ape_set_cache_header() to ape_drupal_goto_alter(). Thank you very much for this catch. The reason we even need the goto_alter is because you can't check for those status codes in hook_page_delivery_callback_alter().
I have also added in automated tests for 301, 302, 403 and 404 server responses.
Comment #19
adammaloneI think you forgot to commit the ape_test directory/test module.
Comment #20
steel-track commented*facepalm*
Right you are! I have committed that and run it through pareview to catch any code style issues. Sorry for any trouble.
Comment #21
adammaloneReally nice effort - your changes are solid, the module works and will be highly useful to many sites. Marking as RTBC.
Comment #22
adammaloneComment #23
kscheirerNo issues found here, nice work and some good suggestions from previous reviewers.
Thanks for your contribution, steel-track!
I updated your account so you can promote this to a full project and also create new projects as either a sandbox or a "full" project.
Here are some recommended readings to help with excellent maintainership:
You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!
Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
Thanks to the dedicated reviewer(s) as well.