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, auto-magic controller/action cache_key. just a regular database data result cached. * cache filename will be: ./app/tmp/cache/views/mockuser_example0_42.php * if $this->userid was 89, the cache filename would be: ./app/tmp/cache/views/mockuser_example0_89.php */ function example0() { // checking cache $d = $this->Ecache->c(); // 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->c($results); } $this->set('myusers', $d); } /** * simple ecache example. just a regular database data result cached. * cache filename will be: ./app/tmp/cache/views/users_list_42.php * if $this->userid was 89, the cache filename would be: ./app/tmp/cache/views/users_list_89.php */ function example1() { // checking cache $d = $this->Ecache->c(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->c($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_42.php * if $this->userid was 89, the cache filename would be: ./app/tmp/cache/views/users_pageelement_89.php * the second will cache content globally, based on whatever cache_key you tell it (not on a per-user basis) * cache filename will be: ./app/tmp/cache/views/myglobalcachefile.php * notice that the content in this example is generated from returned "requestAction"s */ function example2() { // checking cache $d = $this->Ecache->c(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->c($results,'users','pageelement'); } $this->set('user_specific_content', $d); // checking cache $d = $this->Ecache->cf(null,'myglobalcachefile'); // if missing cached content if (empty($d)) { // now get cached content $results = $this->requestAction('/anything/content',array('return')); // writing cache $d = $this->Ecache->cf($results,'myglobalcachefile'); } $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(); } } ?>