Hi,

I have a module:

  $items['getlocations/info'] = array(
    'page callback' => 'getlocations_info',
    'page arguments' => array(2, 3),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  function getlocations_info($lid, $lidkey) {
	return '<p>my html</p>';
  }

If I enter this url '/getlocations/info/2/nid/cache.html' to my browser I see some html output. Is it possible to cache this output?

I enabled caching for 'text/html' and copied genarated rules to .htaccess. All nodes are cached. Only the output from the module is not. I checked folder '/cache' and it does not contain cached output from the module.

Thanks, Martin.

Comments

MPeli’s picture

I tryied the same approach with json

function getlocation_menu() {
  $items['getlocations/info'] = array(
    'page callback' => 'getlocations_info',
    'page arguments' => array(2, 3),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
}
function getlocations_info($lid, $lidkey) {
  $content = '<p>my html</p>';
  drupal_json_output(array('content' => $content));
 }

with url '/getlocations/info/2/nid/cache.json' and no result (the output is not cached into a file). Is this a good approach? How I can cache output from a custom module?

Thank you, Martin.

bgm’s picture

Title: Caching html » Caching html of custom modules

Check in the boost.module code for:

* function boost_transform_url()
* function boost_is_cacheable()
* see if you need to implement: hook_boost_is_cacheable (around line 534)

I have to admit that (while I co-maintain the module), I haven't tested this much. If you can experiment with this and see how it works, it will be nice to have a handbook page on the topic.