userid = $this->myAuthenticaitonSystem(); // populating value with a number, so we can discuss in this example. $this->userid = 42; // mockup value! // initialize Ecache $this->Ecache->startup($this); } /** * simple ecache example. just a regular database data result cached. * cache filename will be: ./app/tmp/cache/views/users_list_0_42_0.php * if $this->userid was 89, the cache filename would be: ./app/tmp/cache/views/users_list_0_89_0.php */ function example1() { // checking cache $d = $this->Ecache->ecache(null,'users','list'); // if missing cached content if (empty($d)) { // now get cached content $cond = array('User.parent_id'=>$this->userid); $results = $this->User->findAll($cond); // writing cache $d = $this->Ecache->ecache($results,'users','list'); } $this->set('myusers',$d); } /** * there are 2 differnt cache calls in this example. * the first is like above, based on the $this->userid. * cache filename will be: ./app/tmp/cache/views/users_pageelement_0_42_0.php * if $this->userid was 89, the cache filename would be: ./app/tmp/cache/views/users_pageelement_0_89_0.php * the second will cache content globally (not on a per-user basis) * cache filename will be: ./app/tmp/cache/views/users_pageelement_0_global_global.php * notice that the content in this example is generated from returned "requestAction"s */ function example2() { // checking cache $d = $this->Ecache->ecache(null,'users','pageelement'); // if missing cached content if (empty($d)) { // now get cached content $results = $this->requestAction('/something/action',array('return')); // writing cache $d = $this->Ecache->ecache($results,'users','pageelement'); } $this->set('user_specific_content',$d); // checking cache $d = $this->Ecache->ecache(null,'users','pageelement',0,'global','global'); // if missing cached content if (empty($d)) { // now get cached content $results = $this->requestAction('/anything/content',array('return')); // writing cache $d = $this->Ecache->ecache($results,'users','pageelement',0,'global','global'); } $this->set('global_content',$d); } /** * This is simply a convenience wrapper for clearing the cache files. * clearing cache deletes: ./app/tmp/cache/view/* * ...often you may need to clear from a model, afterSave() */ function exampleClear() { $this->Ecache->clear(); } } ?>