Sophie

Sophie

distrib > Fedora > 13 > i386 > media > os > by-pkgid > b9acef47780b816a3a75371f0bb1d901 > files > 7

php-ezc-Cache-1.5-1.fc13.noarch.rpm

<?php
/**
 * General example for the Cache component.
 *
 * @package Cache
 * @version 1.5
 * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
 * @license http://ez.no/licenses/new_bsd New BSD License
 */

/**
 * Content view
 */

// Assuming that the ContentView cache has been initialized correctly in the
// index.php:

// First retreive tha cache you want to access from the manager.
$cache = CacheManager::getCache( 'ContentView' );

// Prepare your data identification, use some attributes and a unique ID
$attributes = array(
    'user'      => $user,
    'nodeid'    => $NodeID,
    'offset'    => $Offset,
    'layout'    => $layout,
    'lang'      => $LanguageCode,
    'vmode'     => $ViewMode,
);
$id = getUniqueId( $attributes, $viewParameters );

// Initialize data and try to grep from cache
$data = '';
if ( ( $data = $cache->restore( $id, $attributes ) ) === false ) 
{
    // No data in cache or data has expired. Generate new data...
    // What ever exactly happens to create it in eZp.
    $data = generateMyData();   
    // ... and store it inside the cache
    $cache->store( $id, $attributes, $data );
}
// And that's all! : )
?>