33 function quickcache_restore() {
35 $filename = $GLOBALS[
"QUICKCACHE_DIR"].
"/".$GLOBALS[
"QUICKCACHE_FILEPREFIX"].$GLOBALS[
"quickcache_key"];
38 $cachedata=unserialize(quickcache_fileread($filename));
39 if (is_array($cachedata)) {
41 if ($cachedata[
"quickcache_version"] == $GLOBALS[
"QUICKCACHE_VERSION"]) {
42 if (($cachedata[
"quickcache_expire"] ==
"0") ||
43 ($cachedata[
"quickcache_expire"] >= time()))
46 $GLOBALS[
"quickcachedata_gzdata"] = $cachedata[
"quickcachedata_gzdata"];
47 $GLOBALS[
"quickcachedata_datasize"] = $cachedata[
"quickcachedata_datasize"];
48 $GLOBALS[
"quickcachedata_datacrc"] = $cachedata[
"quickcachedata_datacrc"];
51 quickcache_debug(
"Data in cachefile $filename has expired");
55 quickcache_debug(
"Invalid version of cache-file $filename");
59 quickcache_debug(
"Invalid content of cache-file $filename");
68 function quickcache_write($gzdata, $datasize, $datacrc) {
70 $filename = $GLOBALS[
"QUICKCACHE_DIR"].
"/".$GLOBALS[
"QUICKCACHE_FILEPREFIX"].$GLOBALS[
"quickcache_key"];
74 $cachedata[
"quickcache_version"] = $GLOBALS[
"QUICKCACHE_VERSION"];
75 $cachedata[
"quickcache_expire"] = ($GLOBALS[
"QUICKCACHE_TIME"] > 0) ?
76 time() + $GLOBALS[
"QUICKCACHE_TIME"] :
78 $cachedata[
"quickcachedata_gzdata"] = $gzdata;
79 $cachedata[
"quickcachedata_datasize"] = $datasize;
80 $cachedata[
"quickcachedata_datacrc"] = $datacrc;
83 if (quickcache_filewrite($filename, serialize($cachedata))) {
84 quickcache_debug(
"Successfully wrote cachefile $filename");
86 quickcache_debug(
"Unable to write cachefile $filename");
93 function quickcache_do_gc() {
94 $dp=opendir($GLOBALS[
"QUICKCACHE_DIR"]);
99 quickcache_debug(
"Error opening ". $GLOBALS[
"QUICKCACHE_DIR"] .
" for garbage-collection");
102 while (!(($de=readdir($dp))===FALSE))
106 if (strpos(
"x$de", $GLOBALS[
"QUICKCACHE_FILEPREFIX"])==1) {
107 $filename=$GLOBALS[
"QUICKCACHE_DIR"] .
"/" . $de;
109 $cachedata=unserialize(quickcache_fileread($filename));
112 if (is_array($cachedata)) {
113 if ($cachedata[
"quickcache_expire"]!=
"0" && $cachedata[
"quickcache_expire"]<=time()) {
115 $deleted = @unlink($filename);
117 quickcache_debug(
"Successfully unlinked $filename");
119 quickcache_debug(
"Failed to unlink $filename");
130 function quickcache_do_start() {
138 function quickcache_do_end() {
143 function quickcache_fileread($filename) {
145 $fp=@fopen($filename,
"rb");
147 quickcache_debug(
"Failed to open for read of $filename");
156 while (($tmp=fread($fp, 4096))) {
168 function quickcache_filewrite($filename, $data) {
171 $fpt = @fopen($filename,
"rb");
172 @flock($fpt, LOCK_EX);
175 $fp=@fopen($filename,
"wb+");
178 quickcache_debug(
"Failed to open for write of $filename");
180 fwrite($fp, $data, strlen($data));
186 @flock($fpt, LOCK_UN);