Ejemplo n.º 1
0
 /**
  * Retrieve cached data.
  * @access      public
  * @param       string      $cacheID                The unique ID of the retrieved data.
  * @return      mixed       $result                 Returns a string containg the cached XML data, or FALSE if there is no cached data.
  */
 public function getCachedData($cacheID)
 {
     switch ($this->dataStore) {
         case "file":
             $filename = $this->dataPath . "/" . $cacheID;
             if (file_exists($filename)) {
                 if (time() - filemtime($filename) > $this->updateInterval) {
                     // Cache is out of date, remove the old file
                     self::triggerNotice("Cached file data for " . $cacheID . " is outdated.");
                     @unlink($filename);
                 } else {
                     // Return the cached XML as an array
                     $array = unserialize(file_get_contents($filename));
                     self::triggerNotice("Cached file data for " . $cacheID . " is valid.");
                     return $array;
                 }
             }
             break;
         case "mysql":
             $query = "SELECT cache_xml, UNIX_TIMESTAMP(cache_time) AS cache_time FROM `" . $this->mysqlTable . "` WHERE cache_id = '" . $cacheID . "'";
             $result = mysql_query($query, $this->mysqlString) or self::triggerError("Unable to select cache from database");
             if ($result && mysql_num_rows($result)) {
                 if (time() - mysql_result($result, 0, 'cache_time') > $this->updateInterval) {
                     $query = "DELETE FROM `" . $this->mysqlTable . "` WHERE cache_id = '" . $cacheID . "'";
                     mysql_query($query, $this->mysqlString);
                     self::triggerNotice("Cached mysql data for " . $cacheID . " is outdated.");
                 } else {
                     // Return the cached XML as an array
                     self::triggerNotice("Cached mysql data for " . $cacheID . " is valid.");
                     return parent::convertXmlToArray(mysql_result($result, 0, 'cache_xml'));
                 }
             }
             break;
     }
 }