Cache_Lite::save

Cache_Lite::save() – Save some data in a cache file

Synopsis

require_once 'Cache/Lite.php';

boolean Cache_Lite::save ( string $data , string $id = NULL , string $group = 'default' )

Description

save the given data (which has to be a string if automaticSerialization is set to FALSE (default)).

Parameter

string $data

data to put in a cache file (can be another type than strings if automaticSerialization is TRUE).

string $id

cache id

string $group

name of the cache group

Return value

returns true if no problem

Note

This function can not be called statically.

Example

Usage

<?php
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
    
echo $data;

} else { 
    
    
// No valid cache found (you have to make and save the page)
    
$data '<html><head><title>test</title></head><body><p>this is a test</p></body></html>';
    echo 
$data;
    
$cache->save($data);
    
}

?>
Cache_Lite::get (Previous) Cache_Lite::remove (Next)
Last updated: Tue, 02 Jun 2009 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

Note by: sultan@sultanolama.com
<?php
require_once "Cache/Lite.php";

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

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

    
// Cache hit !
    // Content is in $data
    
echo $data;

} else { 
    
    
// No valid cache found (you have to make and save the page)
    
$data '<html><head><title>test</title></head><body><p>this is a test</p></body></html>';
    echo 
$data;
    
$cache->save($data);
    
}

?>

Note by: sultan@sultanolama.com
<?php
require_once "Cache/Lite.php";

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

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

    
// Cache hit !
    // Content is in $data
    
echo $data;

} else { 
    
    
// No valid cache found (you have to make and save the page)
    
$data '<html><head><title>test</title></head><body><p>this is a test</p></body></html>';
    echo 
$data;
    
$cache->save($data);
    
}

?>