From ae5e13c17464581fa9fecb45ed846adbc69d2490 Mon Sep 17 00:00:00 2001 From: icewing Date: Thu, 20 Mar 2008 12:40:31 +0000 Subject: Marcus Povey * Age checking on cache. git-svn-id: https://code.elgg.org/elgg/trunk@257 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/cache.php | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3