ryxeo-glpi-git / htdocs / lib / cache_lite / Lite / File.php @ 1c14bcc4
Historique | Voir | Annoter | Télécharger (2,64 ko)
1 |
<?php
|
---|---|
2 |
|
3 |
/**
|
4 |
* This class extends Cache_Lite and offers a cache system driven by a master file
|
5 |
*
|
6 |
* With this class, cache validity is only dependent of a given file. Cache files
|
7 |
* are valid only if they are older than the master file. It's a perfect way for
|
8 |
* caching templates results (if the template file is newer than the cache, cache
|
9 |
* must be rebuild...) or for config classes...
|
10 |
* There are some examples in the 'docs/examples' file
|
11 |
* Technical choices are described in the 'docs/technical' file
|
12 |
*
|
13 |
* @package Cache_Lite
|
14 |
* @version $Id: File.php,v 1.3 2005/12/04 16:03:55 fab Exp $
|
15 |
* @author Fabien MARTY <fab@php.net>
|
16 |
*/
|
17 |
|
18 |
require_once(GLPI_CACHE_LITE_DIR.'/Lite.php'); |
19 |
|
20 |
class Cache_Lite_File extends Cache_Lite |
21 |
{ |
22 |
|
23 |
// --- Private properties ---
|
24 |
|
25 |
/**
|
26 |
* Complete path of the file used for controlling the cache lifetime
|
27 |
*
|
28 |
* @var string $_masterFile
|
29 |
*/
|
30 |
var $_masterFile = ''; |
31 |
|
32 |
/**
|
33 |
* Masterfile mtime
|
34 |
*
|
35 |
* @var int $_masterFile_mtime
|
36 |
*/
|
37 |
var $_masterFile_mtime = 0; |
38 |
|
39 |
// --- Public methods ----
|
40 |
|
41 |
/**
|
42 |
* Constructor
|
43 |
*
|
44 |
* $options is an assoc. To have a look at availables options,
|
45 |
* see the constructor of the Cache_Lite class in 'Cache_Lite.php'
|
46 |
*
|
47 |
* Comparing to Cache_Lite constructor, there is another option :
|
48 |
* $options = array(
|
49 |
* (...) see Cache_Lite constructor
|
50 |
* 'masterFile' => complete path of the file used for controlling the cache lifetime(string)
|
51 |
* );
|
52 |
*
|
53 |
* @param array $options options
|
54 |
* @access public
|
55 |
*/
|
56 |
function Cache_Lite_File($options = array(NULL)) |
57 |
{ |
58 |
$options['lifetime'] = 0; |
59 |
$this->Cache_Lite($options); |
60 |
if (isset($options['masterFile'])) { |
61 |
$this->_masterFile = $options['masterFile']; |
62 |
} else {
|
63 |
return $this->raiseError('Cache_Lite_File : masterFile option must be set !'); |
64 |
} |
65 |
if (!($this->_masterFile_mtime = @filemtime($this->_masterFile))) { |
66 |
return $this->raiseError('Cache_Lite_File : Unable to read masterFile : '.$this->_masterFile, -3); |
67 |
} |
68 |
} |
69 |
|
70 |
/**
|
71 |
* Test if a cache is available and (if yes) return it
|
72 |
*
|
73 |
* @param string $id cache id
|
74 |
* @param string $group name of the cache group
|
75 |
* @return string data of the cache (or false if no cache available)
|
76 |
* @access public
|
77 |
*/
|
78 |
function get($id, $group = 'default') |
79 |
{ |
80 |
if ($data = parent::get($id, $group, true)) { |
81 |
if ($filemtime = $this->lastModified()) { |
82 |
if ($filemtime > $this->_masterFile_mtime) { |
83 |
return $data; |
84 |
} |
85 |
} |
86 |
} |
87 |
return false; |
88 |
} |
89 |
|
90 |
} |
91 |
|
92 |
?>
|