User Tools

Site Tools


how_to_use_cache

How To Use Cache

Basic Example

  $my_cache_id = cache::cache_id('my_unique_cache_name', array('dependency'));
  if (($data = cache::get($my_cache_id, 'file', 3600)) === null) {
  
    
    $data = '...';
    
    
    cache::set($my_cache_id, 'file', $data);
  }
  
  echo $data;

Recorder/Player Example

  $my_cache_recorder_id = cache::cache_id('my_unique_cache_name', array('dependency'));
  if (cache::capture($my_cache_recorder_id, 'file', 3600)) {
  
    
    echo 'Some output';
    
  
    cache::end_capture($my_cache_recorder_id);
  }

The number 3600 tells how many seconds the content should be cached.

Please note only the output buffer will be recorded, not any variables set inside.

Dependency parameters will distinguish different cache content by the same id in relation to the environment. E.g. currency stores cache in relation to the selected currency, language stores cache in relation to the selected language, and so on and so on… A list of these depenecies can be found in library/lib_cache.inc.php.

how_to_use_cache.txt · Last modified: 2016/03/30 21:07 by 78.72.180.122