I have functions that need to have very current info but they are very expensive. Going to work on a wrapper to make caching easier to do.

Comments

mikeytown2 created an issue. See original summary.

mikeytown2’s picture

Untested prototype

function httprl_call_user_func_array_cache($callback, array $values = array(), $no_cache, $min_cache_lifetime = 0, $max_cache_lifetime = 0) {
  $cid = __FUNCTION__ . ':' . drupal_base64_encode(serialize(array($callback, $values)));

  $cache = cache_get($cid);
  // Don't use the cache if it's not there, no cache flag is set, or the cached
  // item is older than the max cache lifetime.
  if ( !isset($cache->data)
    || $no_cache
    || (!empty($max_cache_lifetime) && $cache->created < REQUEST_TIME - $max_cache_lifetime)
  ) {
    $cache = new stdClass();
    $cache->data = call_user_func_array($callback, $values);
    cache_set($cid, $cache->data);
  }
  else {
    // Regenerate if cache is older than min cache lifetime.
    if ($cache->created < REQUEST_TIME - $min_cache_lifetime) {
      if (lock_acquire($cid, 10)) {
        $args = func_get_args();
        $args[2] = TRUE;
        httprl_call_user_func_array_async(__FUNCTION__, $args);
      }
    }
  }
  return $cache->data;
}

  • mikeytown2 committed a8ff62e on 7.x-1.x
    Issue #2562143 by mikeytown2: Add in the ability to cache function calls...

  • mikeytown2 committed 37db4be on 7.x-1.x
    Issue #2562143 by mikeytown2: Add in the ability to cache function calls...
mikeytown2’s picture

Status: Active » Fixed
StatusFileSize
new2.44 KB

  • mikeytown2 committed d788fc1 on 6.x-1.x
    Issue #2562143 by mikeytown2: Add in the ability to cache function calls...
mikeytown2’s picture

StatusFileSize
new3.77 KB

Couple of fixes and a new option for this.

  • mikeytown2 committed 4d18e4b on 6.x-1.x
    Issue #2562143 by mikeytonw2: Fix some issues with the microcache...
  • mikeytown2 committed 49b5143 on 7.x-1.x
    Issue #2562143 by mikeytonw2: Fix some issues with the microcache...

Status: Fixed » Closed (fixed)

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