Yii- Caching with CSqlDataprovider -


is possible caching of data sql server queries when using csqldataprovider. if can please provide links documentation it. or if have done please guide.

i did search found nothing :(

there is example of implementing feature

<?php class cachedsqldataprovider extends cdataprovider {         public $querycache;         public $querycachelife;          /**          * @var cdbconnection database connection used in queries.          * defaults null, meaning using yii::app()->db.          */          public $db;         /**          * @var string sql statement used fetching data rows.          */         public $sql;         /**          * @var array parameters (name=>value) bound sql statement.          */         public $params=array();         /**          * @var string name of key field. defaults 'id'.          */         public $keyfield='id';          /**          * constructor.          * @param string $sql sql statement used fetching data rows.          * @param array $config configuration (name=>value) applied initial property values of class.          */         public function __construct($sql,$config=array())         {                 $this->sql=$sql;                 foreach($config $key=>$value)                         $this->$key=$value;         }          /**          * fetches data persistent data storage.          * @return array list of data items          */         protected function fetchdata()         {                 $sql=$this->sql;                 $db=$this->db===null ? yii::app()->db : $this->db;                 $db->active=true;                  if(($sort=$this->getsort())!==false)                 {                         $order=$sort->getorderby();                         if(!empty($order))                         {                                 if(preg_match('/\s+order\s+by\s+[\w\s,]+$/i',$sql))                                         $sql.=', '.$order;                                 else                                         $sql.=' order '.$order;                         }                 }                  if(($pagination=$this->getpagination())!==false)                 {                         $pagination->setitemcount($this->gettotalitemcount());                         $limit=$pagination->getlimit();                         $offset=$pagination->getoffset();                         $sql=$db->getcommandbuilder()->applylimit($sql,$limit,$offset);                 }                  if( $this->querycache == true && $this->querycachelife > 0 )                         $command=$db->cache( $this->querycachelife )->createcommand($sql);                 else                         $command=$db->createcommand($sql);                  foreach($this->params $name=>$value)                         $command->bindvalue($name,$value);                  return $command->queryall();         }          /**          * fetches data item keys persistent data storage.          * @return array list of data item keys.          */         protected function fetchkeys()         {                 $keys=array();                 foreach($this->getdata() $i=>$data)                         $keys[$i]=$data[$this->keyfield];                 return $keys;         }          /**          * calculates total number of data items.          * method invoked when {@link gettotalitemcount()} invoked          * , {@link totalitemcount} not set previously.          * default implementation returns 0.          * may override method return accurate total number of data items.          * @return integer total number of data items.          */         protected function calculatetotalitemcount()         {                 return 0;         } } ?> 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -