zendCachePlugin - 1.0.0

Zend Datacache API wrapper

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
Show source

zendCachePlugin

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

Installation

  • 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
    

Usage

View and partial caching

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

Use it in scripts

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();

?>

Using namespaces

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';

?>

TODO

  • Checking if prefix options is well formed (zend_cache_info is not allowed !!!, avoid :: in prefix name)
  • Using an alternate namespace option