Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/cache
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2012-06-18 13:12:53 +0400
committerBart Visscher <bartv@thisnet.nl>2012-06-18 13:12:53 +0400
commita5a1a9fd4a2f1cd5f2457ba3ab0ceb432da1be33 (patch)
tree83d6307ac2c09130e7609fe6128a1369985b826a /lib/cache
parent617de811f786dd9282ad52c062a58072027f5637 (diff)
Forgot a file
Diffstat (limited to 'lib/cache')
-rw-r--r--lib/cache/fileglobal.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/cache/fileglobal.php b/lib/cache/fileglobal.php
new file mode 100644
index 00000000000..469dd4b6dd4
--- /dev/null
+++ b/lib/cache/fileglobal.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+
+class OC_Cache_FileGlobal{
+ protected function getCacheDir() {
+ $cache_dir = get_temp_dir().'/owncloud-'.OC_Util::getInstanceId().'/';
+ if (!is_dir($cache_dir)) {
+ mkdir($cache_dir);
+ }
+ return $cache_dir;
+ }
+
+ public function get($key) {
+ if ($this->hasKey($key)) {
+ $cache_dir = $this->getCacheDir();
+ return file_get_contents($cache_dir.$key);
+ }
+ return null;
+ }
+
+ public function set($key, $value, $ttl=0) {
+ $cache_dir = $this->getCacheDir();
+ if ($cache_dir and file_put_contents($cache_dir.$key, $value)) {
+ if ($ttl === 0) {
+ $ttl = 86400; // 60*60*24
+ }
+ return touch($cache_dir.$key, time() + $ttl);
+ }
+ return false;
+ }
+
+ public function hasKey($key) {
+ $cache_dir = $this->getCacheDir();
+ if ($cache_dir && is_file($cache_dir.$key)) {
+ $mtime = filemtime($cache_dir.$key);
+ if ($mtime < time()) {
+ unlink($cache_dir.$key);
+ return false;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public function remove($key) {
+ $cache_dir = $this->getCacheDir();
+ if(!$cache_dir){
+ return false;
+ }
+ return unlink($cache_dir.$key);
+ }
+
+ public function clear(){
+ $cache_dir = $this->getCacheDir();
+ if($cache_dir and is_dir($cache_dir)){
+ $dh=opendir($cache_dir);
+ while($file=readdir($dh)){
+ if($file!='.' and $file!='..'){
+ unlink($cache_dir.$file);
+ }
+ }
+ }
+ }
+}