parent
7f1ff3e9e1
commit
80a3f8d066
@ -1,64 +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. |
||||
*/ |
||||
|
||||
class OC_Cache_APC { |
||||
protected $prefix; |
||||
|
||||
public function __construct($global = false) { |
||||
$this->prefix = OC_Util::getInstanceId().'/'; |
||||
if (!$global) { |
||||
$this->prefix .= OC_User::getUser().'/'; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 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); |
||||
if (!$success) { |
||||
return null; |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
public function set($key, $value, $ttl=0) { |
||||
return apc_store($this->getNamespace().$key, $value, $ttl); |
||||
} |
||||
|
||||
public function hasKey($key) { |
||||
return apc_exists($this->getNamespace().$key); |
||||
} |
||||
|
||||
public function remove($key) { |
||||
return apc_delete($this->getNamespace().$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; |
||||
} |
||||
} |
||||
if(!function_exists('apc_exists')) { |
||||
function apc_exists($keys) |
||||
{ |
||||
$result=false; |
||||
apc_fetch($keys, $result); |
||||
return $result; |
||||
} |
||||
} |
@ -0,0 +1,76 @@ |
||||
<?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\Memcache; |
||||
|
||||
class APC extends Cache { |
||||
protected $prefix; |
||||
|
||||
public function __construct($global = false) { |
||||
$this->prefix = \OC_Util::getInstanceId() . '/'; |
||||
if (!$global) { |
||||
$this->prefix .= \OC_User::getUser() . '/'; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 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); |
||||
if (!$success) { |
||||
return null; |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
public function set($key, $value, $ttl = 0) { |
||||
return apc_store($this->getNamespace() . $key, $value, $ttl); |
||||
} |
||||
|
||||
public function hasKey($key) { |
||||
return apc_exists($this->getNamespace() . $key); |
||||
} |
||||
|
||||
public function remove($key) { |
||||
return apc_delete($this->getNamespace() . $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; |
||||
} |
||||
|
||||
static public function isAvailable() { |
||||
if (!extension_loaded('apc')) { |
||||
return false; |
||||
} elseif (!ini_get('apc.enable_cli') && \OC::$CLI) { |
||||
return false; |
||||
}else{ |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (!function_exists('apc_exists')) { |
||||
function apc_exists($keys) { |
||||
$result = false; |
||||
apc_fetch($keys, $result); |
||||
return $result; |
||||
} |
||||
} |
@ -0,0 +1,69 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
namespace OC\Memcache; |
||||
|
||||
abstract class Cache { |
||||
/** |
||||
* get a cache instance |
||||
* |
||||
* @param bool $global |
||||
* @return Cache |
||||
*/ |
||||
static function create($global = false) { |
||||
if (XCache::isAvailable()) { |
||||
return new XCache($global); |
||||
} elseif (APC::isAvailable()) { |
||||
return new APC($global); |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @param bool $global |
||||
*/ |
||||
abstract public function __construct($global); |
||||
|
||||
/** |
||||
* @param string $key |
||||
* @return mixed |
||||
*/ |
||||
abstract public function get($key); |
||||
|
||||
/** |
||||
* @param string $key |
||||
* @param mixed $value |
||||
* @param int $ttl |
||||
* @return mixed |
||||
*/ |
||||
abstract public function set($key, $value, $ttl = 0); |
||||
|
||||
/** |
||||
* @param string $key |
||||
* @return mixed |
||||
*/ |
||||
abstract public function hasKey($key); |
||||
|
||||
/** |
||||
* @param string $key |
||||
* @return mixed |
||||
*/ |
||||
abstract public function remove($key); |
||||
|
||||
/** |
||||
* @param string $prefix |
||||
* @return mixed |
||||
*/ |
||||
abstract public function clear($prefix = ''); |
||||
|
||||
/** |
||||
* @return bool |
||||
*/ |
||||
//static public function isAvailable(); |
||||
} |
@ -1,35 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* ownCloud |
||||
* |
||||
* @author Robin Appelman |
||||
* @copyright 2012 Robin Appelman icewind@owncloud.com |
||||
* |
||||
* This library is free software; you can redistribute it and/or |
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
* License as published by the Free Software Foundation; either |
||||
* version 3 of the License, or any later version. |
||||
* |
||||
* This library 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 along with this library. If not, see <http://www.gnu.org/licenses/>. |
||||
* |
||||
*/ |
||||
|
||||
class Test_Cache_APC extends Test_Cache { |
||||
public function setUp() { |
||||
if(!extension_loaded('apc')) { |
||||
$this->markTestSkipped('The apc extension is not available.'); |
||||
return; |
||||
} |
||||
if(!ini_get('apc.enable_cli') && OC::$CLI) { |
||||
$this->markTestSkipped('apc not available in CLI.'); |
||||
return; |
||||
} |
||||
$this->instance=new OC_Cache_APC(); |
||||
} |
||||
} |
@ -0,0 +1,31 @@ |
||||
<?php |
||||
/** |
||||
* ownCloud |
||||
* |
||||
* @author Robin Appelman |
||||
* @copyright 2012 Robin Appelman icewind@owncloud.com |
||||
* |
||||
* This library is free software; you can redistribute it and/or |
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
* License as published by the Free Software Foundation; either |
||||
* version 3 of the License, or any later version. |
||||
* |
||||
* This library 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 along with this library. If not, see <http://www.gnu.org/licenses/>. |
||||
* |
||||
*/ |
||||
|
||||
class Test_Memcache_XCache extends Test_Cache { |
||||
public function setUp() { |
||||
if (!\OC\Memcache\XCache::isAvailable()) { |
||||
$this->markTestSkipped('The xcache extension is not available.'); |
||||
return; |
||||
} |
||||
$this->instance = new \OC\Memcache\XCache(); |
||||
} |
||||
} |
Loading…
Reference in new issue