Cache

The cache component is a system node that is globally available. It has the purpose of collecting fresh data and serving cached data.

Cached Variable Data

  $cache_token = cache::token('nameofthiscache', $dependencies, $storage, $ttl);
  if (!$variable = cache::get($cache_token, $max_age)) {

    $variable = '...';

    cache::set($cache_token, $variable);
  }

Cached Output Recording

  $cache_token = cache::token('nameofthiscache', $dependencies, $storage, $ttl);
  if (cache::capture($cache_token, $max_age)) {

    echo 'Content that will be recorded';

    cache::end_capture($cache_token);
  }

Dependencies

The dependencies parameter are factors that should vary the cache. Examples: the session language, choice of currency, etc.
The predefined list of dependencies can be found in includes/library/lib_cache.inc.php, but you can also set your own.

  $dependencies = ['language', 'currency']; // Preset example
  $dependencies = [language::$selected['code'], $my_own_variable]; // Custom example

Revisions

Recently Edited Articles
This website uses no cookies and no third party tracking technology. We think we can do better than others and really think about your privacy.