]> git.nbdom.net Git - nb.git/commitdiff
Add lib/php/cache.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 6 Jul 2015 21:01:31 +0000 (22:01 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 6 Jul 2015 21:01:31 +0000 (22:01 +0100)
lib/php/cache.php [new file with mode: 0644]

diff --git a/lib/php/cache.php b/lib/php/cache.php
new file mode 100644 (file)
index 0000000..64a727b
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+require_once('functions.php');
+define('CACHE_DIR',"/tmp/cache.php");
+if (!file_exists(CACHE_DIR)) mkdir(CACHE_DIR,7770);
+
+function cache_get_file($id,$expires) {
+  $file = CACHE_DIR."$id.cache";
+  if (!file_exists($file)) return null;
+
+  $content = file_get_contents($file);
+  if ( filectime($file) < (time()-$expires) ) @unlink($file);
+
+  return $content;
+
+}
+
+function cache_set_file($id,$content) {
+  $file = CACHE_DIR."/$id.cache";
+
+  if (!$ftmp = fopen($file,'w')) {
+    debug("Can't write into $file");
+    return;
+  }
+
+  if (fwrite($ftmp,$content) === FALSE) {
+    debug("Can't write into $file");
+    return;
+  }
+
+  fclose($ftmp);
+  return $file;
+}
+?>