Cache_Lite::get() – Test if a cache is available and (if yes) return it


require_once 'Cache/Lite.php';

string Cache_Lite::get ( string $id , string $group = 'default' , boolean $doNotTestCacheValidity = false )


One of the main method of Cache_Lite : test the validity of a cache file and return it if it's available (FALSE else)


string $id

cache id

string $group

name of the cache group

boolean $doNotTestCacheValidity

if set to TRUE, the cache validity won't be tested

Return value

returns data of the cache (or false if no cache available)


This function can not be called statically.



require_once "Cache/Lite.php";

$options = array(
'cacheDir' => '/tmp/',
'lifeTime' => 7200,
'pearErrorMode' => CACHE_LITE_ERROR_DIE
$cache = new Cache_Lite($options);

if (
$data $cache->get('id_of_the_page')) {

// Cache hit !
    // Content is in $data
    // (...)

} else {

// No valid cache found (you have to make and save the page)
    // (...)


Constructor (Previous) Save some data in a cache file (Next)
Last updated: Sun, 24 Sep 2017 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

Note by: Andrea
If i store a value like 1 or 0 into my cached file, when i get back it with:

if ( $status = $cache->get('status_'.$url) ) {

the condition will evaluate the value 0 (or 1) and not the real status of cache. I other words, the $status value is replaced by my cached value.