Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Implement XCache storage adapter (fixes #2581) #2668

Merged
merged 1 commit into from

2 participants

@marc-mabe

Now ready to merge

(Rebased from #2362)

@weierophinney

How exactly are you running tests? ext/xcache cannot work in the CLI, and I'm not seeing how to run phpunit via a web browser...

@marc-mabe

@weierophinney: I'm using the following start script to run PHPUnit from sapi:

<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');

chdir('/mnt/workspace/zf/zf2/tests');

$argv = $_SERVER['argv'] = array(
    PHP_BINDIR . '/php',
    'ZendTest/Cache/Storage/Adapter/XCacheTest'
);

define('PHPUnit_MAIN_METHOD', 'PHPUnit_TextUI_Command::main');
require '/usr/share/php/PHPUnit/Autoload.php';
PHPUnit_TextUI_Command::main();
@weierophinney

Thanks @marc-mabe -- ran great!

@weierophinney weierophinney merged commit cc3a550 into zendframework:develop
@weierophinney weierophinney was assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
5 library/Zend/Cache/Storage/Adapter/Filesystem.php
@@ -385,7 +385,7 @@ public function optimize()
*/
public function getTotalSpace()
{
- if ($this->totalSpace !== null) {
+ if ($this->totalSpace === null) {
$path = $this->getOptions()->getCacheDir();
ErrorHandler::start();
@@ -394,6 +394,7 @@ public function getTotalSpace()
if ($total === false) {
throw new Exception\RuntimeException("Can't detect total space of '{$path}'", 0, $error);
}
+ $this->totalSpace = $total;
// clean total space buffer on change cache_dir
$events = $this->getEventManager();
@@ -406,7 +407,7 @@ public function getTotalSpace()
$events->detach($handle);
}
};
- $handle = $events->attach($callback);
+ $handle = $events->attach('option', $callback);
}
return $this->totalSpace;
View
500 library/Zend/Cache/Storage/Adapter/XCache.php
@@ -0,0 +1,500 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Cache
+ */
+
+namespace Zend\Cache\Storage\Adapter;
+
+use stdClass;
+use Traversable;
+use Zend\Cache\Exception;
+use Zend\Cache\Storage\AvailableSpaceCapableInterface;
+use Zend\Cache\Storage\Capabilities;
+use Zend\Cache\Storage\ClearByNamespaceInterface;
+use Zend\Cache\Storage\ClearByPrefixInterface;
+use Zend\Cache\Storage\FlushableInterface;
+use Zend\Cache\Storage\IterableInterface;
+use Zend\Cache\Storage\TotalSpaceCapableInterface;
+
+/**
+ * @package Zend_Cache
+ * @subpackage Zend_Cache_Storage
+ * @subpackage Storage
+ */
+class XCache extends AbstractAdapter implements
+ AvailableSpaceCapableInterface,
+ ClearByNamespaceInterface,
+ ClearByPrefixInterface,
+ FlushableInterface,
+ IterableInterface,
+ TotalSpaceCapableInterface
+{
+
+ /**
+ * Backup HTTP authentication properties of $_SERVER array
+ *
+ * @var array
+ */
+ protected $backupAuth = array();
+
+ /**
+ * Total space in bytes
+ *
+ * @var int|float
+ */
+ protected $totalSpace;
+
+ /**
+ * Constructor
+ *
+ * @param null|array|Traversable|ApcOptions $options
+ * @throws Exception\ExceptionInterface
+ */
+ public function __construct($options = null)
+ {
+ if (!extension_loaded('xcache')) {
+ throw new Exception\ExtensionNotLoadedException('Missing ext/xcache');
+ }
+
+ if (PHP_SAPI == 'cli') {
+ throw new Exception\ExtensionNotLoadedException(
+ "ext/xcache isn't available on SAPI 'cli'"
+ );
+ }
+
+ if (ini_get('xcache.var_size') <= 0) {
+ throw new Exception\ExtensionNotLoadedException(
+ "ext/xcache is disabled - see 'xcache.var_size'"
+ );
+ }
+
+ parent::__construct($options);
+ }
+
+ /* options */
+
+ /**
+ * Set options.
+ *
+ * @param array|Traversable|ApcOptions $options
+ * @return XCache
+ * @see getOptions()
+ */
+ public function setOptions($options)
+ {
+ if (!$options instanceof XCacheOptions) {
+ $options = new XCacheOptions($options);
+ }
+
+ return parent::setOptions($options);
+ }
+
+ /**
+ * Get options.
+ *
+ * @return XCacheOptions
+ * @see setOptions()
+ */
+ public function getOptions()
+ {
+ if (!$this->options) {
+ $this->setOptions(new XCacheOptions());
+ }
+ return $this->options;
+ }
+
+ /* TotalSpaceCapableInterface */
+
+ /**
+ * Get total space in bytes
+ *
+ * @return int|float
+ */
+ public function getTotalSpace()
+ {
+ if ($this->totalSpace === null) {
+ $this->totalSpace = 0;
+
+ $this->initAdminAuth();
+ $cnt = xcache_count(XC_TYPE_VAR);
+ for ($i=0; $i < $cnt; $i++) {
+ $info = xcache_info(XC_TYPE_VAR, $i);
+ $this->totalSpace+= $info['size'];
+ }
+ $this->resetAdminAuth();
+ }
+
+ return $this->totalSpace;
+ }
+
+ /* AvailableSpaceCapableInterface */
+
+ /**
+ * Get available space in bytes
+ *
+ * @return int|float
+ */
+ public function getAvailableSpace()
+ {
+ $availableSpace = 0;
+
+ $this->initAdminAuth();
+ $cnt = xcache_count(XC_TYPE_VAR);
+ for ($i = 0; $i < $cnt; $i++) {
+ $info = xcache_info(XC_TYPE_VAR, $i);
+ $availableSpace+= $info['avail'];
+ }
+ $this->resetAdminAuth();
+
+ return $availableSpace;
+ }
+
+
+ /* ClearByNamespaceInterface */
+
+ /**
+ * Remove items by given namespace
+ *
+ * @param string $namespace
+ * @return boolean
+ */
+ public function clearByNamespace($namespace)
+ {
+ $options = $this->getOptions();
+ $prefix = $namespace . $options->getNamespaceSeparator();
+
+ xcache_unset_by_prefix($prefix);
+ return true;
+ }
+
+ /* ClearByPrefixInterface */
+
+ /**
+ * Remove items matching given prefix
+ *
+ * @param string $prefix
+ * @return boolean
+ */
+ public function clearByPrefix($prefix)
+ {
+ $options = $this->getOptions();
+ $prefix = $options->getNamespace() . $options->getNamespaceSeparator() . $prefix;
+
+ xcache_unset_by_prefix($prefix);
+ return true;
+ }
+
+ /* FlushableInterface */
+
+ /**
+ * Flush the whole storage
+ *
+ * @return boolean
+ */
+ public function flush()
+ {
+ $this->initAdminAuth();
+ $cnt = xcache_count(XC_TYPE_VAR);
+ for ($i = 0; $i < $cnt; $i++) {
+ xcache_clear_cache(XC_TYPE_VAR, $i);
+ }
+ $this->resetAdminAuth();
+
+ return true;
+ }
+
+ /* IterableInterface */
+
+ /**
+ * Get the storage iterator
+ *
+ * @return KeyListIterator
+ */
+ public function getIterator()
+ {
+ $options = $this->getOptions();
+ $prefixL = strlen($options->getNamespace() . $options->getNamespaceSeparator());
+ $keys = array();
+
+ $this->initAdminAuth();
+ $cnt = xcache_count(XC_TYPE_VAR);
+ for ($i=0; $i < $cnt; $i++) {
+ $list = xcache_list(XC_TYPE_VAR, $i);
+ foreach ($list['cache_list'] as & $item) {
+ $keys[] = substr($item['name'], $prefixL);
+ }
+ }
+ $this->resetAdminAuth();
+
+ return new KeyListIterator($this, $keys);
+ }
+
+ /* reading */
+
+ /**
+ * Internal method to get an item.
+ *
+ * @param string $normalizedKey
+ * @param boolean $success
+ * @param mixed $casToken
+ * @return mixed Data on success, null on failure
+ * @throws Exception\ExceptionInterface
+ */
+ protected function internalGetItem(& $normalizedKey, & $success = null, & $casToken = null)
+ {
+ $options = $this->getOptions();
+ $prefix = $options->getNamespace() . $options->getNamespaceSeparator();
+ $internalKey = $prefix . $normalizedKey;
+
+ $result = xcache_get($internalKey);
+ $success = ($result !== null);
+
+ if ($success) {
+ $casToken = $result;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Internal method to test if an item exists.
+ *
+ * @param string $normalizedKey
+ * @return boolean
+ * @throws Exception\ExceptionInterface
+ */
+ protected function internalHasItem(& $normalizedKey)
+ {
+ $options = $this->getOptions();
+ $prefix = $options->getNamespace() . $options->getNamespaceSeparator();
+ return xcache_isset($prefix . $normalizedKey);
+ }
+
+ /**
+ * Get metadata of an item.
+ *
+ * @param string $normalizedKey
+ * @return array|boolean Metadata on success, false on failure
+ * @throws Exception\ExceptionInterface
+ */
+ protected function internalGetMetadata(& $normalizedKey)
+ {
+ $options = $this->getOptions();
+ $prefix = $options->getNamespace() . $options->getNamespaceSeparator();
+ $internalKey = $prefix . $normalizedKey;
+
+ if (xcache_isset($internalKey)) {
+
+ $this->initAdminAuth();
+ $cnt = xcache_count(XC_TYPE_VAR);
+ for ($i=0; $i < $cnt; $i++) {
+ $list = xcache_list(XC_TYPE_VAR, $i);
+ foreach ($list['cache_list'] as & $metadata) {
+ if ($metadata['name'] === $internalKey) {
+ $this->normalizeMetadata($metadata);
+ return $metadata;
+ }
+ }
+ }
+ $this->resetAdminAuth();
+ }
+
+ return false;
+ }
+
+ /* writing */
+
+ /**
+ * Internal method to store an item.
+ *
+ * @param string $normalizedKey
+ * @param mixed $value
+ * @return boolean
+ * @throws Exception\ExceptionInterface
+ */
+ protected function internalSetItem(& $normalizedKey, & $value)
+ {
+ $options = $this->getOptions();
+ $prefix = $options->getNamespace() . $options->getNamespaceSeparator();
+ $internalKey = $prefix . $normalizedKey;
+ $ttl = $options->getTtl();
+
+ if (!xcache_set($internalKey, $value, $ttl)) {
+ $type = is_object($value) ? get_class($value) : gettype($value);
+ throw new Exception\RuntimeException(
+ "xcache_set('{$internalKey}', <{$type}>, {$ttl}) failed"
+ );
+ }
+
+ return true;
+ }
+
+ /**
+ * Internal method to remove an item.
+ *
+ * @param string $normalizedKey
+ * @return boolean
+ * @throws Exception\ExceptionInterface
+ */
+ protected function internalRemoveItem(& $normalizedKey)
+ {
+ $options = $this->getOptions();
+ $prefix = $options->getNamespace() . $options->getNamespaceSeparator();
+ $internalKey = $prefix . $normalizedKey;
+
+ return xcache_unset($internalKey);
+ }
+
+ /**
+ * Internal method to increment an item.
+ *
+ * @param string $normalizedKey
+ * @param int $value
+ * @return int|boolean The new value on success, false on failure
+ * @throws Exception\ExceptionInterface
+ */
+ protected function internalIncrementItem(& $normalizedKey, & $value)
+ {
+ $options = $this->getOptions();
+ $prefix = $options->getNamespace() . $options->getNamespaceSeparator();
+ $internalKey = $prefix . $normalizedKey;
+ $ttl = $options->getTtl();
+ $value = (int) $value;
+
+ return xcache_inc($internalKey, $value, $ttl);
+ }
+
+ /**
+ * Internal method to decrement an item.
+ *
+ * @param string $normalizedKey
+ * @param int $value
+ * @return int|boolean The new value on success, false on failure
+ * @throws Exception\ExceptionInterface
+ */
+ protected function internalDecrementItem(& $normalizedKey, & $value)
+ {
+ $options = $this->getOptions();
+ $prefix = $options->getNamespace() . $options->getNamespaceSeparator();
+ $internalKey = $prefix . $normalizedKey;
+ $ttl = $options->getTtl();
+ $value = (int) $value;
+
+ return xcache_dec($internalKey, $value, $ttl);
+ }
+
+ /* status */
+
+ /**
+ * Internal method to get capabilities of this adapter
+ *
+ * @return Capabilities
+ */
+ protected function internalGetCapabilities()
+ {
+ if ($this->capabilities === null) {
+ $marker = new stdClass();
+ $capabilities = new Capabilities(
+ $this,
+ $marker,
+ array(
+ 'supportedDatatypes' => array(
+ 'NULL' => false,
+ 'boolean' => true,
+ 'integer' => true,
+ 'double' => true,
+ 'string' => true,
+ 'array' => true,
+ 'object' => 'object',
+ 'resource' => false,
+ ),
+ 'supportedMetadata' => array(
+ 'internal_key',
+ 'size', 'refcount', 'hits',
+ 'ctime', 'atime', 'hvalue',
+ ),
+ 'minTtl' => 1,
+ 'maxTtl' => (int)ini_get('xcache.var_maxttl'),
+ 'staticTtl' => true,
+ 'ttlPrecision' => 1,
+ 'useRequestTime' => true,
+ 'expiredRead' => false,
+ 'maxKeyLength' => 5182,
+ 'namespaceIsPrefix' => true,
+ 'namespaceSeparator' => $this->getOptions()->getNamespaceSeparator(),
+ )
+ );
+
+ // update namespace separator on change option
+ $this->getEventManager()->attach('option', function ($event) use ($capabilities, $marker) {
+ $params = $event->getParams();
+
+ if (isset($params['namespace_separator'])) {
+ $capabilities->setNamespaceSeparator($marker, $params['namespace_separator']);
+ }
+ });
+
+ $this->capabilities = $capabilities;
+ $this->capabilityMarker = $marker;
+ }
+
+ return $this->capabilities;
+ }
+
+ /* internal */
+
+ /**
+ * Init authentication before calling admin functions
+ *
+ * @return void
+ */
+ protected function initAdminAuth()
+ {
+ $options = $this->getOptions();
+
+ if ($options->getAdminAuth()) {
+ $adminUser = $options->getAdminUser();
+ $adminPass = $options->getAdminPass();
+
+ // backup HTTP authentication properties
+ if (isset($_SERVER['PHP_AUTH_USER'])) {
+ $this->backupAuth['PHP_AUTH_USER'] = $_SERVER['PHP_AUTH_USER'];
+ }
+ if (isset($_SERVER['PHP_AUTH_PW'])) {
+ $this->backupAuth['PHP_AUTH_PW'] = $_SERVER['PHP_AUTH_PW'];
+ }
+
+ // set authentication
+ $_SERVER['PHP_AUTH_USER'] = $adminUser;
+ $_SERVER['PHP_AUTH_PW'] = $adminPass;
+ }
+ }
+
+ /**
+ * Reset authentication after calling admin functions
+ *
+ * @return void
+ */
+ protected function resetAdminAuth()
+ {
+ unset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
+ $_SERVER = $this->backupAuth + $_SERVER;
+ $this->backupAuth = array();
+ }
+
+ /**
+ * Normalize metadata to work with XCache
+ *
+ * @param array $metadata
+ */
+ protected function normalizeMetadata(array & $metadata)
+ {
+ $metadata['internal_key'] = &$metadata['name'];
+ unset($metadata['name']);
+ }
+}
View
151 library/Zend/Cache/Storage/Adapter/XCacheOptions.php
@@ -0,0 +1,151 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Cache
+ */
+
+namespace Zend\Cache\Storage\Adapter;
+
+/**
+ * These are options specific to the XCache adapter
+ *
+ * @category Zend
+ * @package Zend_Cache
+ * @subpackage Storage
+ */
+class XCacheOptions extends AdapterOptions
+{
+ /**
+ * Namespace separator
+ *
+ * @var string
+ */
+ protected $namespaceSeparator = ':';
+
+ /**
+ * Handle admin authentication
+ *
+ * @var boolean
+ */
+ protected $adminAuth = false;
+
+ /**
+ * Username to call admin functions
+ *
+ * @var null|string
+ */
+ protected $adminUser;
+
+ /**
+ * Password to call admin functions
+ *
+ * @var null|string
+ */
+ protected $adminPass;
+
+ /**
+ * Set namespace separator
+ *
+ * @param string $namespaceSeparator
+ * @return XCacheOptions
+ */
+ public function setNamespaceSeparator($namespaceSeparator)
+ {
+ $namespaceSeparator = (string) $namespaceSeparator;
+ $this->triggerOptionEvent('namespace_separator', $namespaceSeparator);
+ $this->namespaceSeparator = $namespaceSeparator;
+ return $this;
+ }
+
+ /**
+ * Get namespace separator
+ *
+ * @return string
+ */
+ public function getNamespaceSeparator()
+ {
+ return $this->namespaceSeparator;
+ }
+
+ /**
+ * Set username to call admin functions
+ *
+ * @param null|string $adminUser
+ * @return XCacheOptions
+ */
+ public function setAdminUser($adminUser)
+ {
+ $adminUser = ($adminUser === null) ? null : (string)$adminUser;
+ if ($this->adminUser !== $adminUser) {
+ $this->triggerOptionEvent('admin_user', $adminUser);
+ $this->adminUser = $adminUser;
+ }
+ return $this;
+ }
+
+ /**
+ * Get username to call admin functions
+ *
+ * @return string
+ */
+ public function getAdminUser()
+ {
+ return $this->adminUser;
+ }
+
+ /**
+ * Enable/Disable admin authentication handling
+ *
+ * @param boolean $adminAuth
+ * @return XCacheOptions
+ */
+ public function setAdminAuth($adminAuth)
+ {
+ $adminAuth = (boolean)$adminAuth;
+ if ($this->adminAuth !== $adminAuth) {
+ $this->triggerOptionEvent('admin_auth', $adminAuth);
+ $this->adminAuth = $adminAuth;
+ }
+ return $this;
+ }
+
+ /**
+ * Get admin authentication enabled
+ *
+ * @return boolean
+ */
+ public function getAdminAuth()
+ {
+ return $this->adminAuth;
+ }
+
+ /**
+ * Set password to call admin functions
+ *
+ * @param null|string $adminPass
+ * @return XCacheOptions
+ */
+ public function setAdminPass($adminPass)
+ {
+ $adminPass = ($adminPass === null) ? null : (string)$adminPass;
+ if ($this->adminPass !== $adminPass) {
+ $this->triggerOptionEvent('admin_pass', $adminPass);
+ $this->adminPass = $adminPass;
+ }
+ return $this;
+ }
+
+ /**
+ * Get password to call admin functions
+ *
+ * @return string
+ */
+ public function getAdminPass()
+ {
+ return $this->adminPass;
+ }
+}
View
3  library/Zend/Cache/Storage/AdapterPluginManager.php
@@ -33,10 +33,11 @@ class AdapterPluginManager extends AbstractPluginManager
*/
protected $invokableClasses = array(
'apc' => 'Zend\Cache\Storage\Adapter\Apc',
+ 'dba' => 'Zend\Cache\Storage\Adapter\Dba',
'filesystem' => 'Zend\Cache\Storage\Adapter\Filesystem',
'memcached' => 'Zend\Cache\Storage\Adapter\Memcached',
'memory' => 'Zend\Cache\Storage\Adapter\Memory',
- 'dba' => 'Zend\Cache\Storage\Adapter\Dba',
+ 'xcache' => 'Zend\Cache\Storage\Adapter\XCache',
'wincache' => 'Zend\Cache\Storage\Adapter\WinCache',
'zendserverdisk' => 'Zend\Cache\Storage\Adapter\ZendServerDisk',
'zendservershm' => 'Zend\Cache\Storage\Adapter\ZendServerShm',
View
7 tests/TestConfiguration.php.dist
@@ -65,9 +65,10 @@ defined('TESTS_ZEND_BARCODE_PDF_SUPPORT') || define('TESTS_ZEND_BARCODE_PDF_SUPP
*/
defined('TESTS_ZEND_CACHE_APC_ENABLED') || define('TESTS_ZEND_CACHE_APC_ENABLED', false);
defined('TESTS_ZEND_CACHE_SQLITE_ENABLED') || define('TESTS_ZEND_CACHE_SQLITE_ENABLED', false);
-defined('TESTS_ZEND_CACHE_XCACHE_ENABLED') || define('TESTS_ZEND_CACHE_XCACHE_ENABLED', false);
-defined('TESTS_ZEND_CACHE_XCACHE_USER') || define('TESTS_ZEND_CACHE_XCACHE_USER', null);
-defined('TESTS_ZEND_CACHE_XCACHE_PASSWORD') || define('TESTS_ZEND_CACHE_XCACHE_PASSWORD', null);
+defined('TESTS_ZEND_CACHE_XCACHE_ENABLED') || define('TESTS_ZEND_CACHE_XCACHE_ENABLED', true);
+defined('TESTS_ZEND_CACHE_XCACHE_ADMIN_AUTH') || define('TESTS_ZEND_CACHE_XCACHE_ADMIN_AUTH', false);
+defined('TESTS_ZEND_CACHE_XCACHE_ADMIN_USER') || define('TESTS_ZEND_CACHE_XCACHE_ADMIN_USER', '');
+defined('TESTS_ZEND_CACHE_XCACHE_ADMIN_PASS') || define('TESTS_ZEND_CACHE_XCACHE_ADMIN_PASS', '');
defined('TESTS_ZEND_CACHE_PLATFORM_ENABLED') || define('TESTS_ZEND_CACHE_PLATFORM_ENABLED', false);
defined('TESTS_ZEND_CACHE_WINCACHE_ENABLED') || define('TESTS_ZEND_CACHE_WINCACHE_ENABLED', false);
defined('TESTS_ZEND_CACHE_ZEND_SERVER_ENABLED') || define('TESTS_ZEND_CACHE_ZEND_SERVER_ENABLED', false);
View
46 tests/ZendTest/Cache/Storage/Adapter/CommonAdapterTest.php
@@ -10,6 +10,7 @@
namespace ZendTest\Cache\Storage\Adapter;
+use Zend\Cache\Storage\AvailableSpaceCapableInterface;
use Zend\Cache\Storage\IterableInterface;
use Zend\Cache\Storage\IteratorInterface;
use Zend\Cache\Storage\StorageInterface;
@@ -19,6 +20,7 @@
use Zend\Cache\Storage\FlushableInterface;
use Zend\Cache\Storage\OptimizableInterface;
use Zend\Cache\Storage\TaggableInterface;
+use Zend\Cache\Storage\TotalSpaceCapableInterface;
use Zend\Http\Header\Expires;
use Zend\Stdlib\ErrorHandler;
@@ -234,7 +236,11 @@ public function testHasItemReturnsFalseOnExpiredItem()
$wait = $ttl + $capabilities->getTtlPrecision();
usleep($wait * 2000000);
- $this->assertFalse($this->_storage->hasItem('key'));
+ if (!$capabilities->getUseRequestTime()) {
+ $this->assertFalse($this->_storage->hasItem('key'));
+ } else {
+ $this->assertTrue($this->_storage->hasItem('key'));
+ }
}
public function testHasItemNonReadable()
@@ -544,12 +550,14 @@ public function testSetAndGetExpiredItem()
$wait = $ttl + $capabilities->getTtlPrecision();
usleep($wait * 2000000);
- if (!$capabilities->getUseRequestTime()) {
- $this->assertNull($this->_storage->getItem('key'));
- } else {
+ if ($capabilities->getUseRequestTime()) {
+ // Can't test much more if the request time will be used
$this->assertEquals('value', $this->_storage->getItem('key'));
+ return;
}
+ $this->assertNull($this->_storage->getItem('key'));
+
$this->_options->setTtl(0);
if ($capabilities->getExpiredRead()) {
$this->assertEquals('value', $this->_storage->getItem('key'));
@@ -1033,4 +1041,34 @@ public function testTagable()
$this->assertFalse($this->_storage->hasItem('key2'));
$this->assertFalse($this->_storage->hasItem('key3'));
}
+
+ public function testGetTotalSpace()
+ {
+ if (!($this->_storage instanceof TotalSpaceCapableInterface)) {
+ $this->markTestSkipped("Storage doesn't implement TotalSpaceCapableInterface");
+ }
+
+ $totalSpace = $this->_storage->getTotalSpace();
+ $this->assertGreaterThan(0, $totalSpace);
+
+ if ($this->_storage instanceof AvailableSpaceCapableInterface) {
+ $availableSpace = $this->_storage->getAvailableSpace();
+ $this->assertGreaterThanOrEqual($availableSpace, $totalSpace);
+ }
+ }
+
+ public function testGetAvailableSpace()
+ {
+ if (!($this->_storage instanceof AvailableSpaceCapableInterface)) {
+ $this->markTestSkipped("Storage doesn't implement AvailableSpaceCapableInterface");
+ }
+
+ $availableSpace = $this->_storage->getAvailableSpace();
+ $this->assertGreaterThanOrEqual(0, $availableSpace);
+
+ if ($this->_storage instanceof TotalSpaceCapableInterface) {
+ $totalSpace = $this->_storage->getTotalSpace();
+ $this->assertLessThanOrEqual($totalSpace, $availableSpace);
+ }
+ }
}
View
81 tests/ZendTest/Cache/Storage/Adapter/XCacheTest.php
@@ -0,0 +1,81 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Cache
+ */
+
+namespace ZendTest\Cache\Storage\Adapter;
+
+use Zend\Cache;
+
+/**
+ * @category Zend
+ * @package Zend_Cache
+ * @subpackage UnitTests
+ * @group Zend_Cache
+ */
+class XCacheTest extends CommonAdapterTest
+{
+
+ protected $backupServerArray;
+
+ public function setUp()
+ {
+ if (!defined('TESTS_ZEND_CACHE_XCACHE_ENABLED') || !TESTS_ZEND_CACHE_XCACHE_ENABLED) {
+ $this->markTestSkipped("Skipped by TestConfiguration (TESTS_ZEND_CACHE_XCACHE_ENABLED)");
+ }
+
+ if (!extension_loaded('xcache')) {
+ try {
+ new Cache\Storage\Adapter\XCache();
+ $this->fail("Expected exception Zend\Cache\Exception\ExtensionNotLoadedException");
+ } catch (Cache\Exception\ExtensionNotLoadedException $e) {
+ $this->markTestSkipped($e->getMessage());
+ }
+ }
+
+ if (PHP_SAPI == 'cli') {
+ try {
+ new Cache\Storage\Adapter\XCache();
+ $this->fail("Expected exception Zend\Cache\Exception\ExtensionNotLoadedException");
+ } catch (Cache\Exception\ExtensionNotLoadedException $e) {
+ $this->markTestSkipped($e->getMessage());
+ }
+ }
+
+ if ((int)ini_get('xcache.var_size') <= 0) {
+ try {
+ new Cache\Storage\Adapter\XCache();
+ $this->fail("Expected exception Zend\Cache\Exception\ExtensionNotLoadedException");
+ } catch (Cache\Exception\ExtensionNotLoadedException $e) {
+ $this->markTestSkipped($e->getMessage());
+ }
+ }
+
+ $this->_options = new Cache\Storage\Adapter\XCacheOptions(array(
+ 'admin_auth' => defined('TESTS_ZEND_CACHE_XCACHE_ADMIN_AUTH') ? TESTS_ZEND_CACHE_XCACHE_ADMIN_AUTH : false,
+ 'admin_user' => defined('TESTS_ZEND_CACHE_XCACHE_ADMIN_USER') ? TESTS_ZEND_CACHE_XCACHE_ADMIN_USER : '',
+ 'admin_pass' => defined('TESTS_ZEND_CACHE_XCACHE_ADMIN_PASS') ? TESTS_ZEND_CACHE_XCACHE_ADMIN_PASS : '',
+ ));
+ $this->_storage = new Cache\Storage\Adapter\XCache();
+ $this->_storage->setOptions($this->_options);
+
+ // dfsdfdsfsdf
+ $this->backupServerArray = $_SERVER;
+
+ parent::setUp();
+ }
+
+ public function tearDown()
+ {
+ if ($this->_storage) {
+ $this->_storage->flush();
+ }
+
+ parent::tearDown();
+ }
+}
Something went wrong with that request. Please try again.