AJAX Cache acts much like imagecache by generating the result of a request on demand and storing it on the filesystem for later reuse. This is useful if you are trying to scale a site that makes many dynamic ajax calls. AJAX cache saves results directly to the files so the web server can serve them directly, rather then bootstrapping Drupal.

AJAX Cache will do nothing by itself. Supporting code must call it.

How to use

First you define the presets you are going to use like this:

<?php
/**
* Test implementation of hook_ajaxcache_presets().
*/
function ajaxcache_ajaxcache_presets() {
  return array(
   
'test' => array(
     
// Name of your function that outputs the data to be cached
     
'callback' => 'ajaxcache_test_callback',
     
// Optional: include file where the callback is located.
      // 'file' => 'include.inc',
      // Optional: file extension to be used when serving the file. Defaults to html.
      // 'extension' => 'json',
      // Optional: file name (without extension) to be used when serving the file. Defaults to ajax.
      // 'filename' => 'test',
   
),
  );
?>

Then, instead of passing javascript the URL that would point to your output function through the menu system, you pass the URL returned by:

<?php
ajaxcache_get_url
($preset_name, $args);
?>

where $preset_name is the name set in your hook_ajaxcache_presets implementation and $args are the arguments passed to your callback function.

Alternatives

Boost

Benefits

- Has the same caching benefits without a need to change your code to use the AJAX Cache API.
- Built in expiration logic.
- Very popular caching module (more support).
- Provides caching for many content types (html, css, js, etc)

Drawbacks

- Doesn't work for authenticated users
- Need to change your .htaccess
- Heavyweight if all you want is to cache AJAX.
- You'll have to implement your own menu callbacks and argument handling.

Originally written by Roger López and contributed by Sony Music

Project Information

Downloads