From 1df1b55b66f0bcc696a1ee9aeb8362dee9889100 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 6 Jan 2014 12:55:56 +0100 Subject: expose memory cache in public api --- lib/private/server.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib') diff --git a/lib/private/server.php b/lib/private/server.php index bee70dec2df..84ee8cadf04 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -136,6 +136,10 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('UserCache', function($c) { return new UserCache(); }); + $this->registerService('MemCache', function ($c) { + $factory = new \OC\Memcache\Factory(); + return $factory->create(); + }); $this->registerService('ActivityManager', function($c) { return new ActivityManager(); }); @@ -295,6 +299,15 @@ class Server extends SimpleContainer implements IServerContainer { return $this->query('UserCache'); } + /** + * Returns an ICache instance + * + * @return \OCP\ICache + */ + function getMemCache() { + return $this->query('MemCache'); + } + /** * Returns the current session * -- cgit v1.2.3 From cd147bb37ae247082442f87b3cdd7d3d752e2d37 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 6 Jan 2014 12:58:43 +0100 Subject: Use APCIterator for Memcache\APC::clear() --- lib/private/memcache/apc.php | 27 ++++++++------------------- lib/private/memcache/apcu.php | 7 ------- 2 files changed, 8 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/private/memcache/apc.php b/lib/private/memcache/apc.php index 575ee4427db..d5bc1498d65 100644 --- a/lib/private/memcache/apc.php +++ b/lib/private/memcache/apc.php @@ -9,15 +9,8 @@ namespace OC\Memcache; class APC extends Cache { - /** - * entries in APC gets namespaced to prevent collisions between owncloud instances and users - */ - protected function getNameSpace() { - return $this->prefix; - } - public function get($key) { - $result = apc_fetch($this->getNamespace() . $key, $success); + $result = apc_fetch($this->getPrefix() . $key, $success); if (!$success) { return null; } @@ -25,26 +18,22 @@ class APC extends Cache { } public function set($key, $value, $ttl = 0) { - return apc_store($this->getNamespace() . $key, $value, $ttl); + return apc_store($this->getPrefix() . $key, $value, $ttl); } public function hasKey($key) { - return apc_exists($this->getNamespace() . $key); + return apc_exists($this->getPrefix() . $key); } public function remove($key) { - return apc_delete($this->getNamespace() . $key); + return apc_delete($this->getPrefix() . $key); } public function clear($prefix = '') { - $ns = $this->getNamespace() . $prefix; - $cache = apc_cache_info('user'); - foreach ($cache['cache_list'] as $entry) { - if (strpos($entry['info'], $ns) === 0) { - apc_delete($entry['info']); - } - } - return true; + $ns = $this->getPrefix() . $prefix; + $ns = preg_quote($ns, '/'); + $iter = new \APCIterator('user', '/^' . $ns . '/'); + return apc_delete($iter); } static public function isAvailable() { diff --git a/lib/private/memcache/apcu.php b/lib/private/memcache/apcu.php index dac0f5f208a..7f780f32718 100644 --- a/lib/private/memcache/apcu.php +++ b/lib/private/memcache/apcu.php @@ -9,13 +9,6 @@ namespace OC\Memcache; class APCu extends APC { - public function clear($prefix = '') { - $ns = $this->getNamespace() . $prefix; - $ns = preg_quote($ns, '/'); - $iter = new \APCIterator('user', '/^'.$ns.'/'); - return apc_delete($iter); - } - static public function isAvailable() { if (!extension_loaded('apcu')) { return false; -- cgit v1.2.3 From 4d65a8089284e4dde09181b56fb45b86c50d6fb5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 6 Jan 2014 13:11:38 +0100 Subject: Remove the static dependency on OC_Util from Memcache --- lib/private/memcache/cache.php | 2 +- lib/private/memcache/factory.php | 13 +++++++++++++ lib/private/server.php | 3 ++- lib/public/iservercontainer.php | 7 +++++++ 4 files changed, 23 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/private/memcache/cache.php b/lib/private/memcache/cache.php index 0ad1cc7ec03..03671b3f240 100644 --- a/lib/private/memcache/cache.php +++ b/lib/private/memcache/cache.php @@ -18,7 +18,7 @@ abstract class Cache implements \ArrayAccess { * @param string $prefix */ public function __construct($prefix = '') { - $this->prefix = \OC_Util::getInstanceId() . '/' . $prefix; + $this->prefix = $prefix; } public function getPrefix() { diff --git a/lib/private/memcache/factory.php b/lib/private/memcache/factory.php index fde7d947567..48c97b59551 100644 --- a/lib/private/memcache/factory.php +++ b/lib/private/memcache/factory.php @@ -9,6 +9,18 @@ namespace OC\Memcache; class Factory { + /** + * @var string $globalPrefix + */ + private $globalPrefix; + + /** + * @param string $globalPrefix + */ + public function __construct($globalPrefix) { + $this->globalPrefix = $globalPrefix; + } + /** * get a cache instance, will return null if no backend is available * @@ -16,6 +28,7 @@ class Factory { * @return \OC\Memcache\Cache */ function create($prefix = '') { + $prefix = $this->globalPrefix . '/' . $prefix; if (XCache::isAvailable()) { return new XCache($prefix); } elseif (APCu::isAvailable()) { diff --git a/lib/private/server.php b/lib/private/server.php index 84ee8cadf04..6b242bddd01 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -137,7 +137,8 @@ class Server extends SimpleContainer implements IServerContainer { return new UserCache(); }); $this->registerService('MemCache', function ($c) { - $factory = new \OC\Memcache\Factory(); + $instanceId = \OC_Util::getInstanceId(); + $factory = new \OC\Memcache\Factory($instanceId); return $factory->create(); }); $this->registerService('ActivityManager', function($c) { diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index b958d2d03f4..7ac5049ef24 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -141,6 +141,13 @@ interface IServerContainer { */ function getCache(); + /** + * Returns an ICache instance + * + * @return \OCP\ICache + */ + function getMemCache(); + /** * Returns the current session * -- cgit v1.2.3 From be7837402d55abc9a6dc801c943c9b642e821dd0 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 8 Jan 2014 15:18:12 +0100 Subject: get the memorycache factory from OCP\Server instead of a cache instance this allows apps to specify a prefix to use --- lib/private/server.php | 11 +++++------ lib/public/cachefactory.php | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 lib/public/cachefactory.php (limited to 'lib') diff --git a/lib/private/server.php b/lib/private/server.php index 6b242bddd01..b5fa9148626 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -136,10 +136,9 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('UserCache', function($c) { return new UserCache(); }); - $this->registerService('MemCache', function ($c) { + $this->registerService('MemCacheFactory', function ($c) { $instanceId = \OC_Util::getInstanceId(); - $factory = new \OC\Memcache\Factory($instanceId); - return $factory->create(); + return new \OC\Memcache\Factory($instanceId); }); $this->registerService('ActivityManager', function($c) { return new ActivityManager(); @@ -303,10 +302,10 @@ class Server extends SimpleContainer implements IServerContainer { /** * Returns an ICache instance * - * @return \OCP\ICache + * @return \OCP\CacheFactory */ - function getMemCache() { - return $this->query('MemCache'); + function getMemCacheFactory() { + return $this->query('MemCacheFactory'); } /** diff --git a/lib/public/cachefactory.php b/lib/public/cachefactory.php new file mode 100644 index 00000000000..bb49aea7f3a --- /dev/null +++ b/lib/public/cachefactory.php @@ -0,0 +1,17 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP; + +interface CacheFactory{ + /** + * @param string $prefix + * @return $return \OCP\ICache + */ + public function create($prefix = ''); +} -- cgit v1.2.3 From 5a2a0426a6c01cffe88c80e0529931a323c699d9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 8 Jan 2014 15:51:40 +0100 Subject: Also update the OCP\IServerContainer --- lib/private/server.php | 2 +- lib/public/iservercontainer.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/private/server.php b/lib/private/server.php index b5fa9148626..6b034a5be9f 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -300,7 +300,7 @@ class Server extends SimpleContainer implements IServerContainer { } /** - * Returns an ICache instance + * Returns an \OCP\CacheFactory instance * * @return \OCP\CacheFactory */ diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 7ac5049ef24..67884bdc3e4 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -142,11 +142,11 @@ interface IServerContainer { function getCache(); /** - * Returns an ICache instance + * Returns an \OCP\CacheFactory instance * - * @return \OCP\ICache + * @return \OCP\CacheFactory */ - function getMemCache(); + function getMemCacheFactory(); /** * Returns the current session -- cgit v1.2.3 From d50c7391d8e78c9555b073fb9ccc6a91d5da34bc Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 9 Jan 2014 13:54:50 +0100 Subject: Use $server->getMemCacheFactory() in ldap connection --- apps/user_ldap/lib/connection.php | 2 +- lib/public/cachefactory.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php index 14dfaa1174d..92168a09ffa 100644 --- a/apps/user_ldap/lib/connection.php +++ b/apps/user_ldap/lib/connection.php @@ -51,7 +51,7 @@ class Connection extends LDAPUtility { $this->configPrefix = $configPrefix; $this->configID = $configID; $this->configuration = new Configuration($configPrefix); - $memcache = new \OC\Memcache\Factory(); + $memcache = \OC::$server->getMemCacheFactory(); if($memcache->isAvailable()) { $this->cache = $memcache->create(); } else { diff --git a/lib/public/cachefactory.php b/lib/public/cachefactory.php index bb49aea7f3a..1bb0ea3dd51 100644 --- a/lib/public/cachefactory.php +++ b/lib/public/cachefactory.php @@ -10,8 +10,17 @@ namespace OCP; interface CacheFactory{ /** + * Get a memory cache instance + * * @param string $prefix * @return $return \OCP\ICache */ public function create($prefix = ''); + + /** + * Check if a memory cache backend is available + * + * @return bool + */ + public function isAvailable(); } -- cgit v1.2.3 From 1ab7ca0a19d5f3984e87f99945d81aecffbbae19 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 24 Jan 2014 16:01:19 +0100 Subject: Fix some phpdoc errors and rename interface --- lib/private/memcache/factory.php | 4 +++- lib/public/cachefactory.php | 26 -------------------------- lib/public/icachefactory.php | 28 ++++++++++++++++++++++++++++ lib/public/iservercontainer.php | 2 +- 4 files changed, 32 insertions(+), 28 deletions(-) delete mode 100644 lib/public/cachefactory.php create mode 100644 lib/public/icachefactory.php (limited to 'lib') diff --git a/lib/private/memcache/factory.php b/lib/private/memcache/factory.php index 48c97b59551..334cf9a1f0e 100644 --- a/lib/private/memcache/factory.php +++ b/lib/private/memcache/factory.php @@ -8,7 +8,9 @@ namespace OC\Memcache; -class Factory { +use \OCP\ICacheFactory; + +class Factory implements ICacheFactory { /** * @var string $globalPrefix */ diff --git a/lib/public/cachefactory.php b/lib/public/cachefactory.php deleted file mode 100644 index 1bb0ea3dd51..00000000000 --- a/lib/public/cachefactory.php +++ /dev/null @@ -1,26 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace OCP; - -interface CacheFactory{ - /** - * Get a memory cache instance - * - * @param string $prefix - * @return $return \OCP\ICache - */ - public function create($prefix = ''); - - /** - * Check if a memory cache backend is available - * - * @return bool - */ - public function isAvailable(); -} diff --git a/lib/public/icachefactory.php b/lib/public/icachefactory.php new file mode 100644 index 00000000000..874f1ec0a59 --- /dev/null +++ b/lib/public/icachefactory.php @@ -0,0 +1,28 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP; + +interface ICacheFactory{ + /** + * Get a memory cache instance + * + * All entries added trough the cache instance will be namespaced by $prefix to prevent collisions between apps + * + * @param string $prefix + * @return \OCP\ICache + */ + public function create($prefix = ''); + + /** + * Check if any memory cache backend is available + * + * @return bool + */ + public function isAvailable(); +} diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 67884bdc3e4..5473f3ee334 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -144,7 +144,7 @@ interface IServerContainer { /** * Returns an \OCP\CacheFactory instance * - * @return \OCP\CacheFactory + * @return \OCP\ICacheFactory */ function getMemCacheFactory(); -- cgit v1.2.3