summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2013-09-19 12:32:32 +0200
committerThomas Tanghus <thomas@tanghus.net>2013-09-19 12:32:32 +0200
commitd5126dd6b4d1d07c1da4cee4de0e857e81df6c73 (patch)
treeedad25845f3e6ad02281220ca8aa69769f72b705 /lib
parent2ef0b58ff6434254510c8be9c940126883022d76 (diff)
parent69c28400b47a3a16ead6fc0d5ee5e2212d0d8ab0 (diff)
downloadnextcloud-server-d5126dd6b4d1d07c1da4cee4de0e857e81df6c73.tar.gz
nextcloud-server-d5126dd6b4d1d07c1da4cee4de0e857e81df6c73.zip
Merge branch 'appframework-master' into server_folder_methods
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php6
-rw-r--r--lib/cache.php23
-rw-r--r--lib/cache/broker.php12
-rw-r--r--lib/cache/file.php13
-rw-r--r--lib/cache/fileglobal.php9
-rw-r--r--lib/cache/fileglobalgc.php5
-rw-r--r--lib/cache/usercache.php77
-rw-r--r--lib/filechunking.php2
-rw-r--r--lib/legacy/cache.php10
-rw-r--r--lib/public/icache.php55
-rw-r--r--lib/public/iservercontainer.php7
-rw-r--r--lib/server.php14
12 files changed, 207 insertions, 26 deletions
diff --git a/lib/base.php b/lib/base.php
index 1720a5fd7e1..0650361be91 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -564,11 +564,13 @@ class OC {
if (OC_Config::getValue('installed', false)) { //don't try to do this before we are properly setup
// register cache cleanup jobs
try { //if this is executed before the upgrade to the new backgroundjob system is completed it will throw an exception
- \OCP\BackgroundJob::registerJob('OC_Cache_FileGlobalGC');
+ \OCP\BackgroundJob::registerJob('OC\Cache\FileGlobalGC');
} catch (Exception $e) {
}
- OC_Hook::connect('OC_User', 'post_login', 'OC_Cache_File', 'loginListener');
+ // NOTE: This will be replaced to use OCP
+ $userSession = \OC_User::getUserSession();
+ $userSession->listen('postLogin', '\OC\Cache\File', 'loginListener');
}
}
diff --git a/lib/cache.php b/lib/cache.php
index 48b9964ba9d..a311f10a00f 100644
--- a/lib/cache.php
+++ b/lib/cache.php
@@ -6,34 +6,36 @@
* See the COPYING-README file.
*/
-class OC_Cache {
+namespace OC;
+
+class Cache {
/**
- * @var OC_Cache $user_cache
+ * @var Cache $user_cache
*/
static protected $user_cache;
/**
- * @var OC_Cache $global_cache
+ * @var Cache $global_cache
*/
static protected $global_cache;
/**
* get the global cache
- * @return OC_Cache
+ * @return Cache
*/
static public function getGlobalCache() {
if (!self::$global_cache) {
- self::$global_cache = new OC_Cache_FileGlobal();
+ self::$global_cache = new Cache\FileGlobal();
}
return self::$global_cache;
}
/**
* get the user cache
- * @return OC_Cache
+ * @return Cache
*/
static public function getUserCache() {
if (!self::$user_cache) {
- self::$user_cache = new OC_Cache_File();
+ self::$user_cache = new Cache\File();
}
return self::$user_cache;
}
@@ -85,7 +87,7 @@ class OC_Cache {
/**
* clear the user cache of all entries starting with a prefix
- * @param string prefix (optional)
+ * @param string $prefix (optional)
* @return bool
*/
static public function clear($prefix='') {
@@ -93,6 +95,11 @@ class OC_Cache {
return $user_cache->clear($prefix);
}
+ /**
+ * creates cache key based on the files given
+ * @param $files
+ * @return string
+ */
static public function generateCacheKeyFromFiles($files) {
$key = '';
sort($files);
diff --git a/lib/cache/broker.php b/lib/cache/broker.php
index a161dbfa3bb..9b7e837e1bc 100644
--- a/lib/cache/broker.php
+++ b/lib/cache/broker.php
@@ -6,8 +6,18 @@
* See the COPYING-README file.
*/
-class OC_Cache_Broker {
+namespace OC\Cache;
+
+class Broker {
+
+ /**
+ * @var \OC\Cache
+ */
protected $fast_cache;
+
+ /**
+ * @var \OC\Cache
+ */
protected $slow_cache;
public function __construct($fast_cache, $slow_cache) {
diff --git a/lib/cache/file.php b/lib/cache/file.php
index 361138e4736..2ab914d17b8 100644
--- a/lib/cache/file.php
+++ b/lib/cache/file.php
@@ -6,24 +6,25 @@
* See the COPYING-README file.
*/
+namespace OC\Cache;
-class OC_Cache_File{
+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());
+ if(\OC_User::isLoggedIn()) {
+ \OC\Files\Filesystem::initMountPoints(\OC_User::getUser());
$subdir = 'cache';
- $view = new \OC\Files\View('/'.OC_User::getUser());
+ $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);
+ $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);
+ \OC_Log::write('core', 'Can\'t get cache storage, user not logged in', \OC_Log::ERROR);
return false;
}
}
diff --git a/lib/cache/fileglobal.php b/lib/cache/fileglobal.php
index c0bd8e45f39..bd049bba4d0 100644
--- a/lib/cache/fileglobal.php
+++ b/lib/cache/fileglobal.php
@@ -6,10 +6,11 @@
* See the COPYING-README file.
*/
+namespace OC\Cache;
-class OC_Cache_FileGlobal{
+class FileGlobal {
static protected function getCacheDir() {
- $cache_dir = get_temp_dir().'/owncloud-'.OC_Util::getInstanceId().'/';
+ $cache_dir = get_temp_dir().'/owncloud-' . \OC_Util::getInstanceId().'/';
if (!is_dir($cache_dir)) {
mkdir($cache_dir);
}
@@ -80,13 +81,13 @@ class OC_Cache_FileGlobal{
}
static public function gc() {
- $last_run = OC_AppConfig::getValue('core', 'global_cache_gc_lastrun', 0);
+ $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);
+ \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);
diff --git a/lib/cache/fileglobalgc.php b/lib/cache/fileglobalgc.php
index a29c31f9063..399dd5e6f94 100644
--- a/lib/cache/fileglobalgc.php
+++ b/lib/cache/fileglobalgc.php
@@ -1,8 +1,9 @@
<?php
+namespace OC\Cache;
-class OC_Cache_FileGlobalGC extends \OC\BackgroundJob\Job{
+class FileGlobalGC extends \OC\BackgroundJob\Job{
public function run($argument){
- OC_Cache_FileGlobal::gc();
+ FileGlobal::gc();
}
}
diff --git a/lib/cache/usercache.php b/lib/cache/usercache.php
new file mode 100644
index 00000000000..baa8820700b
--- /dev/null
+++ b/lib/cache/usercache.php
@@ -0,0 +1,77 @@
+<?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);
+ }
+}
diff --git a/lib/filechunking.php b/lib/filechunking.php
index e6d69273a44..313a6ee87d2 100644
--- a/lib/filechunking.php
+++ b/lib/filechunking.php
@@ -29,7 +29,7 @@ class OC_FileChunking {
protected function getCache() {
if (!isset($this->cache)) {
- $this->cache = new OC_Cache_File();
+ $this->cache = new \OC\Cache\File();
}
return $this->cache;
}
diff --git a/lib/legacy/cache.php b/lib/legacy/cache.php
new file mode 100644
index 00000000000..f915eb516b1
--- /dev/null
+++ b/lib/legacy/cache.php
@@ -0,0 +1,10 @@
+<?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.
+ */
+
+class OC_Cache extends \OC\Cache {
+} \ No newline at end of file
diff --git a/lib/public/icache.php b/lib/public/icache.php
new file mode 100644
index 00000000000..436ee71b2b9
--- /dev/null
+++ b/lib/public/icache.php
@@ -0,0 +1,55 @@
+<?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 OCP;
+
+/**
+ * This interface defines method for accessing the file based user cache.
+ */
+interface ICache {
+
+ /**
+ * Get a value from the user cache
+ *
+ * @param string $key
+ * @return mixed
+ */
+ public function 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);
+
+ /**
+ * Check if a value is set in the user cache
+ *
+ * @param string $key
+ * @return bool
+ */
+ public function hasKey($key);
+
+ /**
+ * Remove an item from the user cache
+ *
+ * @param string $key
+ * @return bool
+ */
+ public function remove($key);
+
+ /**
+ * clear the user cache of all entries starting with a prefix
+ * @param string $prefix (optional)
+ * @return bool
+ */
+ public function clear($prefix = '');
+}
diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php
index 89e71db8d17..cbb9fdf6c2f 100644
--- a/lib/public/iservercontainer.php
+++ b/lib/public/iservercontainer.php
@@ -77,6 +77,13 @@ interface IServerContainer {
function getAppFolder();
/**
+ * Returns an ICache instance
+ *
+ * @return \OCP\ICache
+ */
+ function getCache();
+
+ /**
* Returns the current session
*
* @return \OCP\ISession
diff --git a/lib/server.php b/lib/server.php
index 3454622425a..5c386593f1d 100644
--- a/lib/server.php
+++ b/lib/server.php
@@ -56,6 +56,9 @@ class Server extends SimpleContainer implements IServerContainer {
$view = new View();
return new Root($manager, $view, $user);
});
+ $this->registerService('UserCache', function($c) {
+ return new UserCache();
+ });
}
/**
@@ -66,8 +69,8 @@ class Server extends SimpleContainer implements IServerContainer {
}
/**
- * The current request object holding all information about the request currently being processed
- * is returned from this method.
+ * The current request object holding all information about the request
+ * currently being processed is returned from this method.
* In case the current execution was not initiated by a web request null is returned
*
* @return \OCP\IRequest|null
@@ -130,6 +133,13 @@ class Server extends SimpleContainer implements IServerContainer {
}
return $folder;
+ /**
+ * Returns an ICache instance
+ *
+ * @return \OCP\ICache
+ */
+ function getCache() {
+ return $this->query('UserCache');
}
/**