![]() |
|
zendCachePlugin - 1.0.0Zend Datacache API wrapper |
|
The zendCachePlugin implements Zend caching system in your Symfony applications.
Zend Caching system is availableif your server is running on Zend Platform or Zend Server.
It provide to classes that extends sfCache :
* zendDiskCache for disk cache system
* zendShmCache for shared memory cache system
Install the plugin
$ symfony plugin:install zendCachePlugin
Enable the plugin in your ProjectConfiguration class
# in file SF_ROOT_DIR/config/Projectconfiguration.class.php
class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
/* ... */
$this->enablePlugins( 'zendCachePlugin' );
/* ... */
}
}
Clear the cache
$ symfony cc
To use Zend Data cache for caching your views and partials, update apps/my_app/config/factories.yml :
all: view_cache: class: zendShmCache # or "zendDiskCache" param: automaticCleaningFactor: 0
Clear cache and you are done !
$ symfony cc
There is nothing more in it than in the sfCache API:
<?php
// instanciate a $cache object
$cache = new zendShmCache();
// Storing data in cache
$cache->set( 'a key', $my_data, $user_defined_lifetime );
// Checking if some data is available in cache
if ( $cache->has('some data') )
{
// It's here ! let's retrieve it
$data = $cache->get('some data');
}
else
{
// Do not exists or to late (timed out...)
}
// removing some data
$cache->remove( 'some data');
// cleaning the full cache
$cache->clean();
?>
Namespaces use the prefix option:
<?php
// instanciate to cache objects with different namespaces
$cache_DE = new zendShmCache( array( 'prefix' => 'de' ) );
$cache_FR = new zendShmCache( array( 'prefix' => 'en' ) );
// store datas
$cache_DE->set( 'hello', 'Guten Tag' );
$cache_FR->set( 'hello', 'Bonjour' );
// and retrieve them
echo $cache_DE->get( 'hello' ); // 'Guten Tag';
echo $cache_FR->get( 'hello' ); // 'Bonjour';
?>
prefix options is well formed (zend_cache_info is not allowed !!!, avoid :: in prefix name)namespace option