public function read($url)
 {
     $id = $this->generateCacheId($url);
     $content = $this->cacheDriver->fetch($id);
     if ($content === false) {
         $content = $this->urlReader->read($url);
         $this->cacheDriver->save($id, $content, $this->cacheTime);
     }
     return $content;
 }
Esempio n. 2
0
 /**
  * Listens the preExecute event of Doctrine_Connection_Statement
  *
  * adds the issued query to internal query stack
  * and checks if cached element exists
  *
  * @return boolean
  */
 public function preExecute(Doctrine_Event $event)
 {
     $query = $event->getQuery();
     $data = false;
     // only process SELECT statements
     if (strtoupper(substr(ltrim($query), 0, 6)) != 'SELECT') {
         return false;
     }
     $this->add($query, $event->getInvoker()->getDbh()->getName());
     $data = $this->_driver->fetch(md5(serialize(array($query, $event->getParams()))));
     $this->success = $data ? true : false;
     if (!$data) {
         $rand = mt_rand() / mt_getrandmax();
         if ($rand <= $this->_options['savePropability']) {
             $stmt = $event->getInvoker()->getStatement();
             $stmt->execute($event->getParams());
             $data = $stmt->fetchAll(Doctrine::FETCH_ASSOC);
             $this->success = true;
             $this->_driver->save(md5(serialize(array($query, $event->getParams()))), $data);
         }
     }
     if ($this->success) {
         $this->_data = $data;
         return true;
     }
     return false;
 }