I know that this is and example module only meant to demonstrate and help developers. But I tried working with it and found that it is not working properly. On fresh installation of drupal 7 the authcache_example module does not work for few reasons including:
1. Install file uses old d6 schema implementation techniques.
2. The use of db functions not longer supported such as db_result
3. Breaks on save and/or submit

In addition to that the module lacked:
1. Drupal code standards
2. Access issues are not handled properly.

I worked on the module to convert it to proper D7 module file. I am positive it needs more work, but at least I was able to clean it a little and get it to function on a fresh D7 install. Please see patch and review it. If it passes your review and wish to commit it to the working tree, I would appreciate if you attribute the commit to me.

Members fund testing for the Drupal project. Drupal Association Learn more


awm’s picture

simg’s picture

Thanks Ali, I will check this out when I get some free time.

awm’s picture

Pactch #1 get the module to work without breaking. But, I am still trying to figure out the javascript/Ajax part. It is not very well documented and I am trying to see how it is done in the main authcache module.
That said, I was able to make some progress and get the JS to trigger by:

1. Changing the function _authcache_authcache_example in ajax/authcache.php to

(simple diff)

 function _authcache_authcache_example($vars) {
-  include_once './includes/common.inc';
-  drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH); // Use FULL if needed for additional functions
-  include_once dirname(drupal_get_filename('module', 'authcache_example')) . '/authcache_example.module';
-  return authcache_example_display_block_0();
+ // include_once './includes/common.inc';
+  //drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH); // Use FULL if needed for additional functions
+  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
+ // include_once dirname(drupal_get_filename('module', 'authcache_example')) . '/authcache_example.module';
+  return authcache_example_display_block_example_test();


2. Adding authcache_example_display_block_example_test to authcache_example.module in the following manner (because authcache_example_display_block_0 was not defined anyware)

function authcache_example_display_block_example_test() {
  global $user;
  // $_authcache_is_cacheable seems to be the right variable.
  $block_text = check_plain(db_query("SELECT block_text FROM {authcache_example} WHERE uid = :uid", array(':uid' => $user->uid))->fetchField());

  $output = t("Hello, !user, this is a customized block of content that can be cached by the browser.  Update it <a href=\"!url\">here</a>!", array('!user' => $user->name, '!url' => url("user/$user->uid/authcache_example")));

  $output .= "<p><strong class=\"error\">$block_text</strong></p>";

  return $output;

3. Change authcache_example.js to:

// Does this function have to be in the global scope? I could not get it to evaluate if not placed in global scope
function _authcache_authcache_example(vars) {
  jQuery("#block-authcache-example-example .content").html("<tt><b>[cached by browser]</b></tt><br>" + vars);

// Why can't we use drupal behaviors for the authcahce JS?
function authcacheExampleInit() {
  ajaxJson = {
    // The name of the function to call, both for ajax_authcache.php and
    // this file (see function above). The cookie value will change if
    // the user updates their block (used for max_age cache invalidation)
    'authcache_example' : $.cookie('authcache_example'),

    // Makes browser cache the Ajax response to help reduce server resources
    'max_age' : 3600

  // Perform independent Authcache ajax request
  var ret = Authcache.ajaxRequest(ajaxJson);



However, the function _authcache_authcache_example is triggered before the DOM is ready and is not behaving properly.
I am somewhat familiar with the drupal behavior system and the way authcahe deal with js is still a bit vague to me.
Please let me know whether I am headed in the right direction or not and some pointers would be much appreciated. Also, I placed a few questions in the js code if anyone could help answering them.

simg’s picture

Thanks for this Ali.

Committed to the dev branch.

To answer your questions (as best as they are likely to be answered)

>// Does this function have to be in the global scope? I could not get it to evaluate if not placed in global scope

Probably not, I've yet to actually build an authcache module myself for either D6 or 7, so you now already know more about this than me :)

>// Why can't we use drupal behaviors for the authcahce JS?

Can't see any reason (doesn't mean there isn't one though!). What was there is D6 code and IIRC behaviours are a D7 feature?

simg’s picture

I've been thinking about this.

Behaviours do seem like a good way to go. That said, I'm not convinced that Authcache should be providing the Javascript callback functionality at all. I think it should be separate module that enables personalisation via Javascript.

(Don't worry, I'm not going to arbitrarily ditch the javascript :) )

Anyone else have any thoughts?

znerol’s picture

Status: Needs review » Fixed

The whole JavaScript part was rewritten into behaviors and AJAX is broken out into an optional module in 7.x-2.x.

Status: Fixed » Closed (fixed)

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