Forums / Developer / Cache in a module or operator

Cache in a module or operator

Author Message

Jérôme Vieilledent

Tuesday 10 February 2009 8:38:37 am

Hi

I would like to know if it was possible to cache content fetched in a module or in a operator, directly in PHP or if it was mandatory to use template for that...

Thanx

André R.

Tuesday 10 February 2009 8:49:15 am

Take a look in the eZTemplateCacheBlock class, its in lib/eztemplate/classes/eztemplatecacheblock.php.
Its a helper class to be able to use cache-blocks directly in php, the file contains several examples of use.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Jérôme Vieilledent

Tuesday 10 February 2009 9:18:08 am

Thanks André

I just checked the eZTemplateCacheBlock class. There is an example in the static method <b> eZTemplateCacheBlock::retrieve()</b> :

     list($handler, $data) = eZTemplateCacheBlock::retrieve( array( 'my_cool_key', $id, ), $nodeID, 60 ); // lives 60 seconds
     if ( !$data instanceof eZClusterFileFailure )
     {
         echo $data;
     }
     else
     {
         // ... generate the data
         $data = '...';
         $handler->storeCache( array( 'scope'      => 'template-block',
                                      'binarydata' => $data ) );
     }

But what's the class for <i>$handler</i> in the else section ? I searched in the API doc and I found eZFSFileHandler but the <i>storeCache()</i> method seems to be private.
The doc says : <i>This method is just a continuation of the code in processCache() and is not meant to be called alone since it relies on specific state in the database.</i>
This method is very convenient but will it be still accessible in future releases ?

Thanks