diff options
author | icewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-03-20 12:40:31 +0000 |
---|---|---|
committer | icewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-03-20 12:40:31 +0000 |
commit | ae5e13c17464581fa9fecb45ed846adbc69d2490 (patch) | |
tree | 4c7ea7eff0d3ce07bbc2d2f8673a2b4e9894c502 /engine/lib/cache.php | |
parent | d8f325d0979a97932a7d5ebba0d9c2ccd8dcf6f3 (diff) | |
download | elgg-ae5e13c17464581fa9fecb45ed846adbc69d2490.tar.gz elgg-ae5e13c17464581fa9fecb45ed846adbc69d2490.tar.bz2 |
Marcus Povey <marcus@dushka.co.uk>
* Age checking on cache.
git-svn-id: https://code.elgg.org/elgg/trunk@257 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/cache.php')
-rw-r--r-- | engine/lib/cache.php | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/engine/lib/cache.php b/engine/lib/cache.php index 94637142e..2c7cf4604 100644 --- a/engine/lib/cache.php +++ b/engine/lib/cache.php @@ -117,7 +117,7 @@ // if (!mkdir($path, 0700, true)) throw new IOException("Could not make $path"); // Open the file - if (!file_exists($path . $filename)) return false; + if ((!file_exists($path . $filename)) && ($rw=="rb")) return false; return fopen($path . $filename, $rw); } @@ -166,6 +166,37 @@ public function __destruct() { // TODO: Check size and age, clean up accordingly + $size = 0; + $dir = $this->get_variable("cache_path"); + + // Short circuit if both size and age are unlimited + if (($this->get_variable("max_age")==0) && ($this->get_variable("max_size")==0)) + return; + + $exclude = array(".",".."); + + $files = scandir($dir); + + // Perform cleanup + foreach ($files as $f) + { + if (!in_array($f, $exclude)) + { + $stat = stat($dir.$f); + + // Add size + $size .= $stat['size']; + + // Is this older than my maximum date? + if (($this->get_variable("max_age")>0) && (time() - $stat['mtime'] > $this->get_variable("max_age"))) + unlink($dir.$f); + + + + // TODO: Size + + } + } } } ?>
\ No newline at end of file |