Pluf Framework

Pluf Framework Commit Details


Date:2010-12-11 09:29:14 (14 years 10 days ago)
Author:Mehdi Kabab
Branch:develop, master
Commit:f306f8df225b07137c7f1c36bab622a60fcdf94b
Parents: 4249819190bc4a5ab3e1631b08267cbfd28e0fbe
Message:Show cache files included in debug mode.

Changes:

File differences

src/Pluf/Cache/File.php
2929
3030
3131
32
33
34
35
36
37
38
39
40
41
42
43
44
45
3246
3347
34
48
3549
3650
51
52
3753
3854
3955
......
4864
4965
5066
51
52
53
67
68
69
70
71
72
73
5474
5575
76
5677
5778
5879
......
6687
6788
6889
69
70
71
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
72105
73106
74107
108
75109
76110
77111
......
83117
84118
85119
86
87
88
120
121
122
123
124
125
126
127
128
129
130
89131
90132
*/
class Pluf_Cache_File extends Pluf_Cache
{
/**
* Is debug mode?
*
* @var boolean
*/
private $_debug;
/**
* Mapping key => md5.
*
* @var array
*/
private $_keymap = array();
public function __construct()
{
if (false == Pluf::f('cache_file_folder', false)) {
if (!Pluf::f('cache_file_folder', false)) {
throw new Pluf_Exception_SettingError('"cache_file_folder" setting not defined.');
}
$this->_debug = Pluf::f('debug', false);
}
/**
{
$fname = $this->_keyToFile($key);
$dir = dirname($fname);
if ($timeout == null) $timeout = Pluf::f('cache_timeout', 300);
if (!file_exists($dir)) mkdir($dir, 0777, true);
$expire = time()+$timeout;
if (null === $timeout) {
$timeout = Pluf::f('cache_timeout', 300);
}
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
$expire = $_SERVER['REQUEST_TIME'] + $timeout;
$success = file_put_contents($fname, $expire."\n".serialize($value), LOCK_EX);
chmod($fname, 0777);
return (false === $success) ? false : true;
}
public function get($key, $default=null)
{
$fname = $this->_keyToFile($key);
if (!file_exists($fname)) return $default;
list($timeout, $content) = explode("\n", file_get_contents($fname), 2);
if ($timeout < time()) {
if (!file_exists($fname)) {
return $default;
}
if ($this->_debug) {
ob_start();
include $fname;
$data = ob_get_contents();
ob_end_clean();
} else {
$data = file_get_contents($fname);
}
list($timeout, $content) = explode("\n", $data, 2);
if ($timeout < $_SERVER['REQUEST_TIME']) {
@unlink($fname);
return $default;
}
return unserialize($content);
}
*/
public function _keyToFile($key)
{
$md5 = md5($key);
return Pluf::f('cache_file_folder').'/'.substr($md5, 0, 2)
.'/'.substr($md5, 2, 2).'/'.substr($md5, 4);
if (isset($this->_keymap[$key])) {
$md5 = $this->_keymap[$key];
} else {
$md5 = md5($key);
$this->_keymap[$key] = $md5;
}
return Pluf::f('cache_file_folder') . '/' .
substr($md5, 0, 2) . '/' .
substr($md5, 2, 2) . '/' .
substr($md5, 4);
}
}

Archive Download the corresponding diff file

Branches

Tags

Number of commits:
Page rendered in 0.06173s using 13 queries.