From 9d3e7c987fa66fe2570cd7c6e7efbffaf296745f Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Sun, 27 Jul 2014 06:12:42 +0000 Subject: [PATCH] Cacheoutput : first version : easy method to cache the HTML pages git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1567 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- cacheoutput.php | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 cacheoutput.php diff --git a/cacheoutput.php b/cacheoutput.php new file mode 100644 index 0000000..69dd55b --- /dev/null +++ b/cacheoutput.php @@ -0,0 +1,62 @@ +id = $id; + $this->ttl = $ttl; + $this->cacheCWD = getcwd(); + $cachemethod = "cache$method"; + $this->cache = new $cachemethod (); + $res = $this->cache->read ($id); + // If there is a cache : display it + if ($res !== false) + { + foreach ($res["headers"] as $header) + @header ($header); + echo $res["content"]; + exit; + } + + ob_start (); + $this->saving = true; + // The datas are sent automatically + } + + /** End of saving the datas in cache */ + public function __destruct () + { + // Force the path because it return to / in the destructor + chdir ($this->cacheCWD); + if ($this->saving === true) + { + // Do the saving of the datas + $datas = array ("content"=>ob_get_contents (), + "headers"=>headers_list ()); + $this->cache->write ($this->id, $datas, $this->ttl); + } + } +}