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:

  1. A secondary cache length that can be used for a list of exception paths.
  2. A list of paths that should be excluded from caching by setting the cache control header to no-cache.
  3. 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

skh’s picture

A few quick ones:

  • You have a couple pa review errors: http://pareview.sh/pareview/httpgitdrupalorgsandboxsteel-track2280899git
  • I see a bunch of variable_get and variable_set, however there is no .install file, which should variable_del any of these variables on uninstall.
  • in hook_init:
    • You could use user_is_anonymous instead of the global user variable
    • You could use current_path instead of the $_GET['q']
    • May as well initialize max_age inside the first conditional since it won't be called unless it's met
  • Same notes as above for several other functions
  • Could use a bit more documentation for the hook implementations to say what they're doing.
  • Missing README.txt
  • If the varnish module is required, add it as a requirement in your .info (not sure if it would be)
  • in ape_check_cacheable, you mention checks in order of cost. PHP actually short circuits logical operators, so you could put this into one return statement if you wanted.

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.

skh’s picture

Status: Needs review » Needs work
Taz’s picture

I 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.

steel-track’s picture

All 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.

steel-track’s picture

Status: Needs work » Needs review
steel-track’s picture

Status: Needs review » Reviewed & tested by the community

I 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.

MattWithoos’s picture

Status: Reviewed & tested by the community » Needs work

Hi, 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

steel-track’s picture

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

MattWithoos’s picture

Status: Needs work » Needs review

Right, 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.

stefank’s picture

Hi,

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.

samir_mankar’s picture

Automated Reviews

The Coder Sniffer has found some issues with your code (please check the Drupal coding standards).

ape.module

severity: normal review: style_control_spacing
Line 141: Control statements should have one space between the control keyword and opening parenthesis 

      if(!isset($max_age)) {

Line 144: Control statements should have one space between the control keyword and opening parenthesis [style_control_spacing]

      if(is_null($max_age) && !is_null($new_age)) {

ape.install
  @file block missing (Drupal Docs) [comment_docblock_file]

Manual Reviews

The README.txt file do not follow the guidelines for in-project documentation. Pleas check the README.txt Template for the guidlines.

devd’s picture

Category: Task » Bug report
Issue tags: +git

Hi 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

samir_mankar’s picture

Status: Needs review » Needs work
steel-track’s picture

Issue summary: View changes
Issue tags: -git
steel-track’s picture

Status: Needs work » Needs review
  1. All automated issues have been resolved except for a false positive regarding the page_cache_maximum_age variable.
  2. hook_help() is now implemented.
  3. readme.txt is now per Drupal's preferred standards.
  4. Git project path updated in issue.

I 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.

steel-track’s picture

Automated tests are now included with the module that check the Cache-Control header given a set of configurations.

adammalone’s picture

Status: Needs review » Needs work

I'd be happy to RTBC this if the following are either addressed or have a mitigation.

2 minor nits

  1. testApeHeaders has not declared visibility
  2. Add a link to the module configure page from ape.info
public function testApeHeaders() {
configure = admin/config/development/ape


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=60
I'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:

  • Disregard/cache for a specific time 404s/403s
  • Passthru any requests with sessions which equivocate to logged in users.

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.

function ape_drupal_goto_alter(&$path, &$options, &$http_response_code) {
  $max_age = NULL;
  if ($http_response_code == 301) {
    $max_age = variable_get('ape_301_lifetime', 0);
  }
  elseif ($http_response_code == 302) {
    $max_age = variable_get('ape_302_lifetime', 0);
  }
  ape_cache_set($max_age);
  ape_set_cache_header($max_age);
}
steel-track’s picture

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

adammalone’s picture

I think you forgot to commit the ape_test directory/test module.

steel-track’s picture

*facepalm*

Right you are! I have committed that and run it through pareview to catch any code style issues. Sorry for any trouble.

adammalone’s picture

Status: Needs work » Reviewed & tested by the community

Really nice effort - your changes are solid, the module works and will be highly useful to many sites. Marking as RTBC.

adammalone’s picture

Category: Bug report » Task
kscheirer’s picture

Status: Reviewed & tested by the community » Fixed

No 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.