Example #1
0
 /**
  * Expire cache
  *
  * I'd love to use threads to do that, but I'm not forcing 
  * compiling PHP to use that.
  *
  * @param boolean $verbose mode
  *
  * @return boolean
  */
 public function expireCache($verbose = false)
 {
     // if first run ...
     if (!$this->_last_expired_at) {
         $this->_last_expired_at = mktime();
         if ($verbose) {
             echo "First time running cache expiration\n";
         }
     }
     // if current time is lower than the last time ran plust timeout
     if (mktime() < $this->_last_expired_at + $this->_timeout) {
         if ($verbose) {
             echo "Not checking cache timeouts\n";
         }
         return false;
     }
     if ($verbose) {
         echo "Checking cache timeouts.\n";
     }
     foreach ($this->_prepared_cache as $key => $cache) {
         if (mktime() > intval($cache["timestamp"]) + $this->_timeout) {
             Model::closeCursor($cache["statement"]);
             unset($this->_prepared_cache[$key]);
         }
     }
     $this->_last_expired_at = mktime();
     return true;
 }