summaryrefslogtreecommitdiffstats
path: root/lib/cache
diff options
context:
space:
mode:
Diffstat (limited to 'lib/cache')
-rw-r--r--lib/cache/broker.php63
-rw-r--r--lib/cache/file.php118
-rw-r--r--lib/cache/fileglobal.php106
-rw-r--r--lib/cache/fileglobalgc.php9
-rw-r--r--lib/cache/usercache.php77
5 files changed, 0 insertions, 373 deletions
diff --git a/lib/cache/broker.php b/lib/cache/broker.php
deleted file mode 100644
index 9b7e837e1bc..00000000000
--- a/lib/cache/broker.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?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.
- */
-
-namespace OC\Cache;
-
-class Broker {
-
- /**
- * @var \OC\Cache
- */
- protected $fast_cache;
-
- /**
- * @var \OC\Cache
- */
- protected $slow_cache;
-
- public function __construct($fast_cache, $slow_cache) {
- $this->fast_cache = $fast_cache;
- $this->slow_cache = $slow_cache;
- }
-
- public function get($key) {
- if ($r = $this->fast_cache->get($key)) {
- return $r;
- }
- return $this->slow_cache->get($key);
- }
-
- public function set($key, $value, $ttl=0) {
- if (!$this->fast_cache->set($key, $value, $ttl)) {
- if ($this->fast_cache->hasKey($key)) {
- $this->fast_cache->remove($key);
- }
- return $this->slow_cache->set($key, $value, $ttl);
- }
- return true;
- }
-
- public function hasKey($key) {
- if ($this->fast_cache->hasKey($key)) {
- return true;
- }
- return $this->slow_cache->hasKey($key);
- }
-
- public function remove($key) {
- if ($this->fast_cache->remove($key)) {
- return true;
- }
- return $this->slow_cache->remove($key);
- }
-
- public function clear($prefix='') {
- $this->fast_cache->clear($prefix);
- $this->slow_cache->clear($prefix);
- }
-}
diff --git a/lib/cache/file.php b/lib/cache/file.php
deleted file mode 100644
index 2ab914d17b8..00000000000
--- a/lib/cache/file.php
+++ /dev/null
@@ -1,118 +0,0 @@
-<?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.
- */
-
-namespace OC\Cache;
-
-class File {
- protected $storage;
- protected function getStorage() {
- if (isset($this->storage)) {
- return $this->storage;
- }
- if(\OC_User::isLoggedIn()) {
- \OC\Files\Filesystem::initMountPoints(\OC_User::getUser());
- $subdir = 'cache';
- $view = new \OC\Files\View('/' . \OC_User::getUser());
- if(!$view->file_exists($subdir)) {
- $view->mkdir($subdir);
- }
- $this->storage = new \OC\Files\View('/' . \OC_User::getUser().'/'.$subdir);
- return $this->storage;
- }else{
- \OC_Log::write('core', 'Can\'t get cache storage, user not logged in', \OC_Log::ERROR);
- return false;
- }
- }
-
- public function get($key) {
- $result = null;
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
- if ($this->hasKey($key)) {
- $storage = $this->getStorage();
- $result = $storage->file_get_contents($key);
- }
- \OC_FileProxy::$enabled = $proxyStatus;
- return $result;
- }
-
- public function set($key, $value, $ttl=0) {
- $storage = $this->getStorage();
- $result = false;
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
- if ($storage and $storage->file_put_contents($key, $value)) {
- if ($ttl === 0) {
- $ttl = 86400; // 60*60*24
- }
- $result = $storage->touch($key, time() + $ttl);
- }
- \OC_FileProxy::$enabled = $proxyStatus;
- return $result;
- }
-
- public function hasKey($key) {
- $storage = $this->getStorage();
- if ($storage && $storage->is_file($key)) {
- $mtime = $storage->filemtime($key);
- if ($mtime < time()) {
- $storage->unlink($key);
- return false;
- }
- return true;
- }
- return false;
- }
-
- public function remove($key) {
- $storage = $this->getStorage();
- if(!$storage) {
- return false;
- }
- return $storage->unlink($key);
- }
-
- public function clear($prefix='') {
- $storage = $this->getStorage();
- if($storage and $storage->is_dir('/')) {
- $dh=$storage->opendir('/');
- if(is_resource($dh)) {
- while (($file = readdir($dh)) !== false) {
- if($file!='.' and $file!='..' and ($prefix==='' || strpos($file, $prefix) === 0)) {
- $storage->unlink('/'.$file);
- }
- }
- }
- }
- return true;
- }
-
- public function gc() {
- $storage = $this->getStorage();
- if($storage and $storage->is_dir('/')) {
- $now = time();
- $dh=$storage->opendir('/');
- if(!is_resource($dh)) {
- return null;
- }
- while (($file = readdir($dh)) !== false) {
- if($file!='.' and $file!='..') {
- $mtime = $storage->filemtime('/'.$file);
- if ($mtime < $now) {
- $storage->unlink('/'.$file);
- }
- }
- }
- }
- }
-
- public static function loginListener() {
- $c = new self();
- $c->gc();
- }
-}
diff --git a/lib/cache/fileglobal.php b/lib/cache/fileglobal.php
deleted file mode 100644
index bd049bba4d0..00000000000
--- a/lib/cache/fileglobal.php
+++ /dev/null
@@ -1,106 +0,0 @@
-<?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.
- */
-
-namespace OC\Cache;
-
-class FileGlobal {
- static protected function getCacheDir() {
- $cache_dir = get_temp_dir().'/owncloud-' . \OC_Util::getInstanceId().'/';
- if (!is_dir($cache_dir)) {
- mkdir($cache_dir);
- }
- return $cache_dir;
- }
-
- protected function fixKey($key) {
- return str_replace('/', '_', $key);
- }
-
- public function get($key) {
- $key = $this->fixKey($key);
- if ($this->hasKey($key)) {
- $cache_dir = self::getCacheDir();
- return file_get_contents($cache_dir.$key);
- }
- return null;
- }
-
- public function set($key, $value, $ttl=0) {
- $key = $this->fixKey($key);
- $cache_dir = self::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) {
- $key = $this->fixKey($key);
- $cache_dir = self::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 = self::getCacheDir();
- if(!$cache_dir) {
- return false;
- }
- $key = $this->fixKey($key);
- return unlink($cache_dir.$key);
- }
-
- public function clear($prefix='') {
- $cache_dir = self::getCacheDir();
- $prefix = $this->fixKey($prefix);
- if($cache_dir and is_dir($cache_dir)) {
- $dh=opendir($cache_dir);
- if(is_resource($dh)) {
- while (($file = readdir($dh)) !== false) {
- if($file!='.' and $file!='..' and ($prefix==='' || strpos($file, $prefix) === 0)) {
- unlink($cache_dir.$file);
- }
- }
- }
- }
- }
-
- static public function gc() {
- $last_run = \OC_AppConfig::getValue('core', 'global_cache_gc_lastrun', 0);
- $now = time();
- if (($now - $last_run) < 300) {
- // only do cleanup every 5 minutes
- return;
- }
- \OC_AppConfig::setValue('core', 'global_cache_gc_lastrun', $now);
- $cache_dir = self::getCacheDir();
- if($cache_dir and is_dir($cache_dir)) {
- $dh=opendir($cache_dir);
- if(is_resource($dh)) {
- while (($file = readdir($dh)) !== false) {
- if($file!='.' and $file!='..') {
- $mtime = filemtime($cache_dir.$file);
- if ($mtime < $now) {
- unlink($cache_dir.$file);
- }
- }
- }
- }
- }
- }
-}
diff --git a/lib/cache/fileglobalgc.php b/lib/cache/fileglobalgc.php
deleted file mode 100644
index 399dd5e6f94..00000000000
--- a/lib/cache/fileglobalgc.php
+++ /dev/null
@@ -1,9 +0,0 @@
-<?php
-
-namespace OC\Cache;
-
-class FileGlobalGC extends \OC\BackgroundJob\Job{
- public function run($argument){
- FileGlobal::gc();
- }
-}
diff --git a/lib/cache/usercache.php b/lib/cache/usercache.php
deleted file mode 100644
index baa8820700b..00000000000
--- a/lib/cache/usercache.php
+++ /dev/null
@@ -1,77 +0,0 @@
-<?php
-/**
- * Copyright (c) 2013 Thomas Tanghus (thomas@tanghus.net)
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-namespace OC\Cache;
-
-/**
- * This interface defines method for accessing the file based user cache.
- */
-class UserCache implements \OCP\ICache {
-
- /**
- * @var \OC\Cache\File $userCache
- */
- protected $userCache;
-
- public function __construct() {
- $this->userCache = new File();
- }
-
- /**
- * Get a value from the user cache
- *
- * @param string $key
- * @return mixed
- */
- public function get($key) {
- return $this->userCache->get($key);
- }
-
- /**
- * Set a value in the user cache
- *
- * @param string $key
- * @param mixed $value
- * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
- * @return bool
- */
- public function set($key, $value, $ttl = 0) {
- if (empty($key)) {
- return false;
- }
- return $this->userCache->set($key, $value, $ttl);
- }
-
- /**
- * Check if a value is set in the user cache
- *
- * @param string $key
- * @return bool
- */
- public function hasKey($key) {
- return $this->userCache->hasKey($key);
- }
-
- /**
- * Remove an item from the user cache
- *
- * @param string $key
- * @return bool
- */
- public function remove($key) {
- return $this->userCache->remove($key);
- }
-
- /**
- * clear the user cache of all entries starting with a prefix
- * @param string $prefix (optional)
- * @return bool
- */
- public function clear($prefix = '') {
- return $this->userCache->clear($prefix);
- }
-}