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

Révisions

Articles récemment édités
Ce site n'utilise aucun cookie ni aucune technologie de suivi tierce. Nous pensons pouvoir faire mieux que les autres et nous nous soucions vraiment de votre vie privée.