![]() |
Xataface 2.0
Xataface Application Framework
|
00001 <?php 00002 /*------------------------------------------------------------------------------- 00003 * Xataface Web Application Framework 00004 * Copyright (C) 2005-2008 Web Lite Solutions Corp (shannah@sfu.ca) 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 *------------------------------------------------------------------------------- 00020 */ 00021 require_once 'Cache/Lite.php'; 00022 require_once 'Dataface/Application.php'; 00023 class Dataface_PageCache extends Cache_Lite { 00024 00025 var $tables; 00026 function Dataface_PageCache($tables=array()){ 00027 $this->tables =& $tables; 00028 $app =& Dataface_Application::getInstance(); 00029 $params = array( 00030 'cacheDir' => $app->_conf['cache_dir'].'/dataface_page_cache', 00031 'lifeTime' => 3600); 00032 00033 00034 if ( !file_exists($params['cacheDir']) ){ 00035 mkdir($params['cacheDir'], true); 00036 } 00037 if ( !file_exists($params['cacheDir']) ){ 00038 throw new Exception("Cannot create directory '".$params['cacheDir']."'", E_USER_ERROR); 00039 } else { 00040 //echo $params['cacheDir']; 00041 } 00042 $this->Cache_Lite($params); 00043 00044 00045 } 00046 00047 function dbmtime(){ 00048 $tables =& $this->tables; 00049 $lookup = array_flip($tables); 00050 $app =& Dataface_Application::getInstance(); 00051 $res = mysql_query("SHOW TABLE STATUS", $app->_db); 00052 $latestMod = 0; 00053 while ( $row = mysql_fetch_array($res) ){ 00054 if ( (sizeof($tables) === 0 || isset( $lookup[$row['Name']] ) ) && strtotime($row['Update_time']) > $latestMod ){ 00055 $latestMod = strtotime($row['Update_time']); 00056 } 00057 } 00058 00059 return $latestMod; 00060 00061 } 00062 00063 function get($id){ 00064 $mtime = $this->dbmtime(); 00065 $this->_setFileName($id,'default'); 00066 if ( $mtime < $this->lastModified() ){ 00067 return parent::get($id); 00068 } else { 00069 return false; 00070 } 00071 } 00072 00073 00074 } 00075