summaryrefslogtreecommitdiffstats
path: root/lib/private/cache
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2015-05-08 14:05:54 +0200
committerArthur Schiwon <blizzz@owncloud.com>2015-05-08 14:05:54 +0200
commit3de7f58321462601755cac3745dca5c25edc6f2b (patch)
treec697ed363974c6d5a8556cad25da4d44e682ea28 /lib/private/cache
parent90611e65943adc9d58ce04b5e08978c6dc122a68 (diff)
downloadnextcloud-server-3de7f58321462601755cac3745dca5c25edc6f2b.tar.gz
nextcloud-server-3de7f58321462601755cac3745dca5c25edc6f2b.zip
remove file cache classes and its tests
Diffstat (limited to 'lib/private/cache')
-rw-r--r--lib/private/cache/broker.php80
-rw-r--r--lib/private/cache/file.php174
-rw-r--r--lib/private/cache/fileglobal.php107
-rw-r--r--lib/private/cache/fileglobalgc.php80
-rw-r--r--lib/private/cache/usercache.php93
5 files changed, 0 insertions, 534 deletions
diff --git a/lib/private/cache/broker.php b/lib/private/cache/broker.php
deleted file mode 100644
index a52fb220f00..00000000000
--- a/lib/private/cache/broker.php
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-/**
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Thomas Tanghus <thomas@tanghus.net>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-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/private/cache/file.php b/lib/private/cache/file.php
deleted file mode 100644
index c70698eb7f8..00000000000
--- a/lib/private/cache/file.php
+++ /dev/null
@@ -1,174 +0,0 @@
-<?php
-/**
- * @author Arthur Schiwon <blizzz@owncloud.com>
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Björn Schießle <schiessle@owncloud.com>
- * @author Jörn Friedrich Dreyer <jfd@butonic.de>
- * @author Michael Gapczynski <GapczynskiM@gmail.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Thomas Tanghus <thomas@tanghus.net>
- * @author Vincent Petry <pvince81@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Cache;
-
-use OC\Files\Filesystem;
-use OC\Files\View;
-use OCP\Security\ISecureRandom;
-
-class File {
- protected $storage;
-
- /**
- * Returns the cache storage for the logged in user
- *
- * @return \OC\Files\View cache storage
- */
- protected function getStorage() {
- if (isset($this->storage)) {
- return $this->storage;
- }
- if (\OC_User::isLoggedIn()) {
- $rootView = new View();
- $user = \OC::$server->getUserSession()->getUser();
- Filesystem::initMountPoints($user->getUID());
- if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) {
- $rootView->mkdir('/' . $user->getUID() . '/cache');
- }
- $this->storage = new View('/' . $user->getUID() . '/cache');
- return $this->storage;
- } else {
- \OC_Log::write('core', 'Can\'t get cache storage, user not logged in', \OC_Log::ERROR);
- throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in');
- }
- }
-
- /**
- * @param string $key
- */
- public function get($key) {
- $result = null;
- if ($this->hasKey($key)) {
- $storage = $this->getStorage();
- $result = $storage->file_get_contents($key);
- }
- return $result;
- }
-
- /**
- * Returns the size of the stored/cached data
- *
- * @param string $key
- * @return int
- */
- public function size($key) {
- $result = 0;
- if ($this->hasKey($key)) {
- $storage = $this->getStorage();
- $result = $storage->filesize($key);
- }
- return $result;
- }
-
- /**
- * @param string $key
- */
- public function set($key, $value, $ttl = 0) {
- $storage = $this->getStorage();
- $result = false;
- // unique id to avoid chunk collision, just in case
- $uniqueId = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(
- 16,
- ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER
- );
-
- // use part file to prevent hasKey() to find the key
- // while it is being written
- $keyPart = $key . '.' . $uniqueId . '.part';
- if ($storage and $storage->file_put_contents($keyPart, $value)) {
- if ($ttl === 0) {
- $ttl = 86400; // 60*60*24
- }
- $result = $storage->touch($keyPart, time() + $ttl);
- $result &= $storage->rename($keyPart, $key);
- }
- return $result;
- }
-
- public function hasKey($key) {
- $storage = $this->getStorage();
- if ($storage && $storage->is_file($key) && $storage->isReadable($key)) {
- return true;
- }
- return false;
- }
-
- /**
- * @param string $key
- */
- 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/private/cache/fileglobal.php b/lib/private/cache/fileglobal.php
deleted file mode 100644
index b808c0dd8ff..00000000000
--- a/lib/private/cache/fileglobal.php
+++ /dev/null
@@ -1,107 +0,0 @@
-<?php
-/**
- * @author Arthur Schiwon <blizzz@owncloud.com>
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Jörn Friedrich Dreyer <jfd@butonic.de>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Thomas Tanghus <thomas@tanghus.net>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-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);
- }
-
- /**
- * @param string $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;
- }
-
- /**
- * @param string $key
- * @param string $value
- */
- 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) && is_readable($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);
- }
- }
- }
- }
- }
-}
diff --git a/lib/private/cache/fileglobalgc.php b/lib/private/cache/fileglobalgc.php
deleted file mode 100644
index 0d966282383..00000000000
--- a/lib/private/cache/fileglobalgc.php
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-/**
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
- * @author Thomas Tanghus <thomas@tanghus.net>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Cache;
-
-use OC\BackgroundJob\Job;
-use OCP\IConfig;
-
-class FileGlobalGC extends Job {
- // only do cleanup every 5 minutes
- const CLEANUP_TTL_SEC = 300;
-
- public function run($argument) {
- $this->gc(\OC::$server->getConfig(), $this->getCacheDir());
- }
-
- protected function getCacheDir() {
- return get_temp_dir() . '/owncloud-' . \OC_Util::getInstanceId() . '/';
- }
-
- /**
- * @param string $cacheDir
- * @param int $now
- * @return string[]
- */
- public function getExpiredPaths($cacheDir, $now) {
- $files = scandir($cacheDir);
- $files = array_filter($files, function ($file) {
- return $file != '.' and $file != '..';
- });
- $paths = array_map(function ($file) use ($cacheDir) {
- return $cacheDir . $file;
- }, $files);
- return array_values(array_filter($paths, function ($path) use ($now) {
- return is_file($path) and (filemtime($path) < $now);
- }));
- }
-
- /**
- * @param \OCP\IConfig $config
- * @param string $cacheDir
- */
- public function gc(IConfig $config, $cacheDir) {
- $lastRun = $config->getAppValue('core', 'global_cache_gc_lastrun', 0);
- $now = time();
- if (($now - $lastRun) < self::CLEANUP_TTL_SEC) {
- return;
- }
- $config->setAppValue('core', 'global_cache_gc_lastrun', $now);
- if (!is_dir($cacheDir)) {
- return;
- }
- $paths = $this->getExpiredPaths($cacheDir, $now);
- array_walk($paths, function($file) {
- if (file_exists($file)) {
- unlink($file);
- }
- });
- }
-}
diff --git a/lib/private/cache/usercache.php b/lib/private/cache/usercache.php
deleted file mode 100644
index bbf5b7eda69..00000000000
--- a/lib/private/cache/usercache.php
+++ /dev/null
@@ -1,93 +0,0 @@
-<?php
-/**
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Scrutinizer Auto-Fixer <auto-fixer@scrutinizer-ci.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Thomas Tanghus <thomas@tanghus.net>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-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 string $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);
- }
-}