Strategies for generating Zend Cache Keys

Posted by emeraldjava on Stack Overflow See other posts from Stack Overflow or by emeraldjava
Published on 2010-05-19T17:48:09Z Indexed on 2010/05/19 17:50 UTC
Read the original article Hit count: 270

Filed under:

ATM i'm manually generating a cache key based on the method name and parameters, then follow to the normal cache pattern. This is all done in the Controller and i'm calling a model class that 'extends Zend_Db_Table_Abstract'.

public function indexAction()
{
    $cache = Zend_Registry::get('cache');

    $individualleaguekey = sprintf("getIndividualLeague_%d_%s",$leagueid,$division->code);
    if(!$leaguetable = $cache->load($individualleaguekey))
    {
        $table = new Model_DbTable_Raceresult();
        $leaguetable = $table->getIndividualLeague($leagueid,$division,$races);
        $cache->save($leaguetable, $individualleaguekey);
    }
    $this->view->leaguetable = $leaguetable;
....

I want to avoid the duplication of parameters to the cache creation method and also to the model method, so i'm thinking of moving the caching logic away from my controller class and into model class packaged in './model/DbTable', but this seems incorrect since the DB model should only handle SQL operations. Any suggestions on how i can implement a clean patterned solution?

© Stack Overflow or respective owner

Related posts about zend-framework