I am using this module to convert the ajax post requests to ajax get request so that they can be cache in varnish. The conversion is very smooth but those urls are not cached by varnish.
After a bit debugging I found that varnish uses the information provided in headers, and for those get request we have request header set "Cache-Control: no-cache", so they are invalidated by varnish.
I am trying to resolve this and hopefully will come up with a solution.
Comments
Comment #1
gaurav.goyal commentedPatch attached.
Used the below code for adding headers and it works for me..
Thanks for the module, a good one..:)
Comment #2
gaurav.goyal commentedComment #3
gaurav.goyal commentedChanging the tags, as i realized this module does not provide this feature.
Comment #4
leon kessler commentedHi Gaurav,
Thanks for reporting this. At first I didn't think this module should be responsible for cache-control headers. But thinking about it more, I don't see why not. Anyone using this module is only doing so to help with caching, so makes sense to have this as part of the module.
A few comments on your patch though:
1) This should be moved to views_ajax_get.module
2) Let's add a line in the docblock comment explaining what the function is doing.
3) We need to check that the Views isn't excluded in variable_get('views_ajax_get_exemptions'). We don't wanna send cache-control headers when it's a POST request.
4) We should also add in drupal_page_is_cacheable(TRUE); to let other modules know the request is cacheable.
hook_views_api isn't required, we're only implementing an alter hook.
Comment #5
gaurav.goyal commentedHi leon.nk,
Thanks for the detailed feedback.
Yes I completely agree with you, this should be a part of this module.
Comment #6
gaurav.goyal commentedHi leon,
Attached is the updated patch.
Comment #7
leon kessler commentedOkay great!
Looks good, sorry couple more nitpicks :-)
Should be Implements hook_views_ajax_data_alter(). As per https://www.drupal.org/coding-standards/docs#hookimpl
Also, "Implements hook_views_ajax_data_alter()." should appear first
Let's change variable_get('cache_lifetime', 300) to variable_get('cache_lifetime', 0)
To mimic core's default value for this variable.
Comment #8
gaurav.goyal commentedHi leon,
Ahh..my bad..thanks for pointing out..:)
Patch is modified, i think now it looks more cleaner...:)
Comment #10
leon kessler commentedGreat thanks a lot! Patch committed to dev.
Comment #12
leon kessler commentedCorrected something in the commit. The use of
drupal_page_is_cacheable()was incorrect. We should be checking that caching is enabled before setting the headers (and not setting it explicitly). Otherwise we will be caching responses for logged in users, which could lead to unexpected results.Comment #13
leon kessler commentedComment #14
leon kessler commentedPatch was wrong way round!