Skip to content
This repository was archived by the owner on Feb 17, 2022. It is now read-only.

7.x 2.x Function: at_cache

Andy Truong edited this page Jan 21, 2014 · 9 revisions

Without at_cache()

function your_data_provider($reset = FALSE) {
  $cache_id = '…';
  $bin = 'bin';
  $expire = strtotime('+ 15 minutes');

  if (!$reset && $cache = cache_get($cache_id, $bin)) {
    return $cache->data;
  }

  $data = your_logic();

  cache_set($data, $cache_id, $bin, $expire);

  return $data;
}

With at_cache(), your logic becomes cleaner:

function your_data_provider() {
  return your_logic();
}

$data = at_cache(array('cache_id' => '…'), 'your_data_provider');

Clone this wiki locally