Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
PageCache.php
Go to the documentation of this file.
1 <?php
2 /*-------------------------------------------------------------------------------
3  * Xataface Web Application Framework
4  * Copyright (C) 2005-2008 Web Lite Solutions Corp (shannah@sfu.ca)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *-------------------------------------------------------------------------------
20  */
21 require_once 'Cache/Lite.php';
22 require_once 'Dataface/Application.php';
23 class Dataface_PageCache extends Cache_Lite {
24 
25  var $tables;
26  function Dataface_PageCache($tables=array()){
27  $this->tables =& $tables;
29  $params = array(
30  'cacheDir' => $app->_conf['cache_dir'].'/dataface_page_cache',
31  'lifeTime' => 3600);
32 
33 
34  if ( !file_exists($params['cacheDir']) ){
35  mkdir($params['cacheDir'], true);
36  }
37  if ( !file_exists($params['cacheDir']) ){
38  throw new Exception("Cannot create directory '".$params['cacheDir']."'", E_USER_ERROR);
39  } else {
40  //echo $params['cacheDir'];
41  }
42  $this->Cache_Lite($params);
43 
44 
45  }
46 
47  function dbmtime(){
49  $lookup = array_flip($tables);
51  $res = mysql_query("SHOW TABLE STATUS", $app->_db);
52  $latestMod = 0;
53  while ( $row = mysql_fetch_array($res) ){
54  if ( (sizeof($tables) === 0 || isset( $lookup[$row['Name']] ) ) && strtotime($row['Update_time']) > $latestMod ){
55  $latestMod = strtotime($row['Update_time']);
56  }
57  }
58 
59  return $latestMod;
60 
61  }
62 
63  function get($id){
64  $mtime = $this->dbmtime();
65  $this->_setFileName($id,'default');
66  if ( $mtime < $this->lastModified() ){
67  return parent::get($id);
68  } else {
69  return false;
70  }
71  }
72 
73 
74 }
75