aboutsummaryrefslogtreecommitdiff
path: root/services/cacheservice.php
diff options
context:
space:
mode:
authormensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2007-12-12 16:29:16 +0000
committermensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2007-12-12 16:29:16 +0000
commitd582054c77b22daeb08d2bff17794b9a69a20dd4 (patch)
treed6e7cef8639da6f573cd0b21a5316abf5af24fac /services/cacheservice.php
downloadsemanticscuttle-d582054c77b22daeb08d2bff17794b9a69a20dd4.tar.gz
semanticscuttle-d582054c77b22daeb08d2bff17794b9a69a20dd4.tar.bz2
import of scuttle 0.7.2
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@1 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'services/cacheservice.php')
-rw-r--r--services/cacheservice.php38
1 files changed, 38 insertions, 0 deletions
diff --git a/services/cacheservice.php b/services/cacheservice.php
new file mode 100644
index 0000000..fe66d38
--- /dev/null
+++ b/services/cacheservice.php
@@ -0,0 +1,38 @@
+<?php
+class CacheService {
+ var $basedir;
+ var $fileextension = '.cache';
+
+ function &getInstance() {
+ static $instance;
+
+ if (!isset($instance))
+ $instance =& new CacheService();
+
+ return $instance;
+ }
+
+ function CacheService() {
+ $this->basedir = $GLOBALS['dir_cache'];
+ }
+
+ function Start($hash, $time = 300) {
+ $cachefile = $this->basedir .'/'. $hash . $this->fileextension;
+ if (file_exists($cachefile) && time() < filemtime($cachefile) + $time) {
+ @readfile($cachefile);
+ echo "\n<!-- Cached: ". date('r', filemtime($cachefile)) ." -->\n";
+ unset($cachefile);
+ exit;
+ }
+ ob_start("ob_gzhandler");
+ }
+
+ function End($hash) {
+ $cachefile = $this->basedir .'/'. $hash . $this->fileextension;
+ $handle = fopen($cachefile, 'w');
+ fwrite($handle, ob_get_contents());
+ fclose($handle);
+ ob_flush();
+ }
+}
+?> \ No newline at end of file