| [ Indice ] |
Riferimento incrociato di Joomla! 1.5.14 - VM 1.1.4Servizio fornito da VMItalia |
[Vedi sommario] [Stampa] [Vedi testo]
1 <?PHP 2 /** 3 * patTemplate Template cache that stores data on filesystem 4 * 5 * $Id: File.php 10381 2008-06-01 03:35:53Z pasamio $ 6 * 7 * @package patTemplate 8 * @subpackage Caches 9 * @author Stephan Schmidt <schst@php.net> 10 */ 11 12 // Check to ensure this file is within the rest of the framework 13 defined('JPATH_BASE') or die(); 14 15 /** 16 * patTemplate Template cache that stores data on filesystem 17 * 18 * $Id: File.php 10381 2008-06-01 03:35:53Z pasamio $ 19 * 20 * Possible parameters for the cache are: 21 * - cacheFolder : set the folder from which to load the cache 22 * - lifetime : seconds for which the cache is valid, if set to auto, it will check 23 * whether the cache is older than the original file (if the reader supports this) 24 * - prefix for the filenames 25 * 26 * @package patTemplate 27 * @subpackage Caches 28 * @author Stephan Schmidt <schst@php.net> 29 */ 30 class patTemplate_TemplateCache_File extends patTemplate_TemplateCache 31 { 32 /** 33 * parameters of the cache 34 * 35 * @access private 36 * @var array 37 */ 38 var $_params = array( 39 'cacheFolder' => './cache', 40 'lifetime' => 'auto', 41 'prefix' => '', 42 'filemode' => null 43 ); 44 45 46 /** 47 * load template from cache 48 * 49 * @access public 50 * @param string cache key 51 * @param integer modification time of original template 52 * @return array|boolean either an array containing the templates or false cache could not be loaded 53 */ 54 function load($key, $modTime = -1) 55 { 56 $filename = $this->_getCachefileName( $key ); 57 if (!file_exists($filename) || !is_readable($filename)) { 58 return false; 59 } 60 61 $generatedOn = filemtime( $filename ); 62 $ttl = $this->getParam('lifetime'); 63 if ($ttl == 'auto') { 64 if ($modTime < 1) { 65 return false; 66 } 67 if ($modTime > $generatedOn) { 68 return false; 69 } 70 return unserialize(file_get_contents($filename)); 71 } elseif(is_int( $ttl)) { 72 if ($generatedOn + $ttl < time()) { 73 return false; 74 } 75 return unserialize( file_get_contents( $filename ) ); 76 } 77 78 return false; 79 } 80 81 /** 82 * write template to cache 83 * 84 * @access public 85 * @param string cache key 86 * @param array templates to store 87 * @return boolean true on success 88 */ 89 function write( $key, $templates ) 90 { 91 $cacheFile = $this->_getCachefileName($key); 92 $fp = @fopen($cacheFile, 'w'); 93 if (!$fp) { 94 return false; 95 } 96 flock( $fp, LOCK_EX ); 97 fputs( $fp, serialize($templates)); 98 flock( $fp, LOCK_UN ); 99 $filemode = $this->getParam('filemode'); 100 if ($filemode !== null) { 101 chmod($cacheFile, $filemode); 102 } 103 return true; 104 } 105 106 /** 107 * get the cache filename 108 * 109 * @access private 110 * @param string cache key 111 * @return string cache file name 112 */ 113 function _getCachefileName( $key ) 114 { 115 return $this->getParam( 'cacheFolder' ) . '/' . $this->getParam( 'prefix' ).$key . '.cache'; 116 } 117 } 118 ?>
titolo
Descrizione
Corpo
titolo
Descrizione
Corpo
titolo
Descrizione
Corpo
titolo
Corpo
| Generato il: Mon Oct 19 20:29:27 2009 | Generato con PHPXref 0.7 |