Skip to content

Commit fcbc798

Browse files
committed
Merge pull request #140 from fbonzon/sqlite
Improved driver_stats() for sqlite driver
2 parents 599cdc1 + ac2e059 commit fcbc798

File tree

3 files changed

+106
-127
lines changed

3 files changed

+106
-127
lines changed

phpfastcache/3.0.0/drivers/files.php

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ function __construct($config = array()) {
2828
}
2929

3030
}
31-
31+
3232
private function encodeFilename($keyword) {
33-
return trim(trim(preg_replace("/[^a-zA-Z0-9]+/","_",$keyword),"_"));
33+
return trim(trim(preg_replace("/[^a-zA-Z0-9]+/","_",$keyword),"_"));
3434
// return rtrim(base64_encode($keyword), '=');
3535
}
36-
36+
3737
private function decodeFilename($filename) {
38-
return $filename;
38+
return $filename;
3939
// return base64_decode($filename);
4040
}
4141

@@ -44,8 +44,8 @@ private function decodeFilename($filename) {
4444
*/
4545
private function getFilePath($keyword, $skip = false) {
4646
$path = $this->getPath();
47-
48-
$filename = $this->encodeFilename($keyword);
47+
48+
$filename = $this->encodeFilename($keyword);
4949
$folder = substr($filename,0,2);
5050
$path = rtrim($path,"/")."/".$folder;
5151
/*
@@ -59,7 +59,7 @@ private function getFilePath($keyword, $skip = false) {
5959

6060
} elseif(!is_writeable($path)) {
6161
if(!chmod($path,$this->__setChmodAuto())) {
62-
throw new Exception("PLEASE CHMOD ".$this->getPath()." - 0777 OR ANY WRITABLE PERMISSION!",92);
62+
throw new Exception("PLEASE CHMOD ".$this->getPath()." - 0777 OR ANY WRITABLE PERMISSION!",92);
6363
}
6464
}
6565
}
@@ -68,7 +68,6 @@ private function getFilePath($keyword, $skip = false) {
6868
return $file_path;
6969
}
7070

71-
7271
function driver_set($keyword, $value = "", $time = 300, $option = array() ) {
7372
$file_path = $this->getFilePath($keyword);
7473
// echo "<br>DEBUG SET: ".$keyword." - ".$value." - ".$time."<br>";
@@ -99,9 +98,6 @@ function driver_set($keyword, $value = "", $time = 300, $option = array() ) {
9998
}
10099
}
101100

102-
103-
104-
105101
function driver_get($keyword, $option = array()) {
106102

107103
$file_path = $this->getFilePath($keyword);
@@ -162,19 +158,19 @@ function driver_stats($option = array()) {
162158
$object = $this->decode($this->readfile($file_path));
163159
if($this->isExpired($object)) {
164160
@unlink($file_path);
165-
$removed = $removed + $size;
161+
$removed += $size;
166162
}
167-
$total = $total + $size;
163+
$total += $size;
168164
}
169165
} // end read subdir
170166
} // end if
171167
} // end while
172168

173-
$res['size'] = $total - $removed;
169+
$res['size'] = $total - $removed;
174170
$res['info'] = array(
175-
"Total" => $total,
176-
"Removed" => $removed,
177-
"Current" => $res['size'],
171+
"Total [bytes]" => $total,
172+
"Expired and removed [bytes]" => $removed,
173+
"Current [bytes]" => $res['size'],
178174
);
179175
return $res;
180176
}
@@ -212,10 +208,8 @@ function driver_clean($option = array()) {
212208
} // end if
213209
} // end while
214210

215-
216211
}
217212

218-
219213
function driver_isExisting($keyword) {
220214
$file_path = $this->getFilePath($keyword,true);
221215
if(!@file_exists($file_path)) {
@@ -232,15 +226,11 @@ function driver_isExisting($keyword) {
232226
}
233227

234228
function isExpired($object) {
235-
236229
if(isset($object['expired_time']) && time() >= $object['expired_time']) {
237230
return true;
238231
} else {
239232
return false;
240233
}
241234
}
242235

243-
244-
245-
246236
}

0 commit comments

Comments
 (0)