Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Check if cache file exists and unset vars to free memory

  • Loading branch information...
commit adddc106c47cca98ce015d11cfa6bfdf7f8363d8 1 parent 496d5e6
unknown authored
Showing with 9 additions and 6 deletions.
  1. +9 −6 catalog/includes/functions/cache.php
View
15 catalog/includes/functions/cache.php
@@ -22,11 +22,11 @@ function write_cache(&$var, $filename) {
// try to open the file
if ($fp = @fopen($filename, 'w')) {
// obtain a file lock to stop corruptions occuring
- flock($fp, 2); // LOCK_EX
+ flock($fp, LOCK_EX);
// write serialized data
- fputs($fp, json_encode(base64_encode(addslashes(gzdeflate($var)))));
+ fputs($fp, json_encode(base64_encode(addslashes(gzdeflate($var)))));
// release the file lock
- flock($fp, 3); // LOCK_UN
+ flock($fp, LOCK_UN);
fclose($fp);
$success = true;
}
@@ -54,16 +54,19 @@ function read_cache(&$var, $filename, $auto_expire = false){
}
}
+ if (!file_exists($filename)) {
+
// read in serialized data
$szdata = gzinflate(file_get_contents($filename));
-
+
// unserialze the data
$var = json_decode(stripslashes(base64_decode($szdata)));
-
$success = true;
}
-
+ unset($var);
+ unset($szdata);
return $success;
+ }
////
//! Get data from the cache or the database.
Please sign in to comment.
Something went wrong with that request. Please try again.