Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi to everybody.
I'm using authcache and filecache with a drupal 7 installation, everithing is going fine and the pages are cached well.
The problem is that i have a custom module with a couple of pages created with the hook_menu().
So for example i have this page: '/get/data' witch print (not return) some data for an ajax request, this page with the normal drupal cache has been cached, but not with authcache.
So giving a look to the headers the request is always:
Cache-Control max-age=0
And the answer si always:
Cache-Control no-cache, must-revalidate, post-check=0, pre-check=0
X-Drupal-Cache MISS
How can include this page/menu item in the authcache+filecache system?
Regards
Comments
Comment #1
znerol CreditAttribution: znerol commentedThe first thing you should ensure is that your menu-callback does not call
exit()
. If you need to terminate a request earlry, then use drupal_exit. This will invoke all exit hooks (see hook_exit) and will allow authcache to store the page.If this is not the cause, then I recommend to enable the Authcache Debug module and enable logging to watchdog for authcache enabled roles. You find the setting in Administration » Configuration » System » Authcache » Debug. The log can be accessed from Administration » Reports » Recent log messages.
Comment #2
andrea.cavattoni CreditAttribution: andrea.cavattoni commentedThank you, it helped me a lot.
First of all drupal_exit was necessary for call authcache and second the headers must be setted with "drupal_add_http_header" and not with php "headers".
So the code looks like this:
Hope it helps.
Comment #3
znerol CreditAttribution: znerol commentedPerfect! When working with JSON, you might consider reusing drupal_json_output. This actually sets the proper header and also does a check-for-null before the echo. Also note that it shouldn't be necessary to terminate the request early. There are some JSON examples in drupal core and none of them calls
drupal_exit
directly. For reference here is howuser/autocomplete
works:The
hook_menu
implementation (user_menu):And the corresponding page callback (user_autocomplete):
Comment #4
znerol CreditAttribution: znerol commented