Index: core/install/install_toolkit.php
===================================================================
--- core/install/install_toolkit.php
+++ core/install/install_toolkit.php
@@ -970,7 +970,11 @@
$cache_handler = $this->Application->makeClass('kCache');
$cache_handlers = Array (
- 'Fake' => 'None', 'Memcache' => 'Memcached', 'XCache' => 'XCache', 'Apc' => 'Alternative PHP Cache'
+ 'Fake' => 'None',
+ 'Memcache' => 'Memcache',
+ 'Memcached' => 'Memcached',
+ 'XCache' => 'XCache',
+ 'Apc' => 'Alternative PHP Cache',
);
foreach ($cache_handlers AS $class_prefix => $title) {
Index: core/kernel/utility/cache.php
===================================================================
--- core/kernel/utility/cache.php
+++ core/kernel/utility/cache.php
@@ -104,6 +104,10 @@
// get cache handler class to use
$handler_class = kUtil::getSystemConfig()->get('CacheHandler', '') . 'CacheHandler';
+ if ( $handler_class == 'MemcacheCacheHandler' && PHP_VERSION_ID >= 70000 ) {
+ $handler_class = 'MemcachedCacheHandler';
+ }
+
// defined cache handler doesn't exist -> use default
if ( !class_exists($handler_class) ) {
$handler_class = 'FakeCacheHandler';
@@ -823,6 +827,118 @@
}
}
+ class MemcachedCacheHandler extends kCacheHandler {
+
+ /**
+ * Memcache connection
+ *
+ * @var Memcached
+ * @access protected
+ */
+ protected $_handler = null;
+
+ /**
+ * MemcachedCacheHandler constructor.
+ *
+ * @param kCache $parent Parent.
+ * @param string $default_servers Default servers.
+ */
+ public function __construct(kCache $parent, $default_servers = '')
+ {
+ parent::__construct($parent);
+
+ $this->cachingType = CACHING_TYPE_MEMORY;
+
+ $memcached_servers = kUtil::getSystemConfig()->get('MemcacheServers', $default_servers);
+
+ if ( $memcached_servers && class_exists('Memcached') ) {
+ $this->_enabled = true;
+ $this->_handler = new Memcached();
+ $servers = explode(';', $memcached_servers);
+
+ foreach ( $servers as $server ) {
+ if ( preg_match('/(.*):([\d]+)$/', $server, $regs) ) {
+ // Possible format: "hostname:port" OR "unix:///path/to/socket:0".
+ $server = $regs[1];
+ $port = $regs[2];
+ }
+ else {
+ $port = 11211;
+ }
+
+ $this->_handler->addServer($server, $port);
+ }
+
+ // Verify, that memcache server is working.
+ if ( !$this->_handler->set('test', 1) ) {
+ $this->_enabled = false;
+ }
+ }
+ }
+
+ /**
+ * Retrieves value from cache
+ *
+ * @param string|array $name Name.
+ *
+ * @return mixed
+ * @access public
+ */
+ public function get($name)
+ {
+ if ( is_array($name) ) {
+ return $this->_handler->getMulti($name);
+ }
+
+ return $this->_handler->get($name);
+ }
+
+ /**
+ * Stores value in cache
+ *
+ * @param string $name Name.
+ * @param mixed $value Value.
+ * @param integer $expiration Expiration.
+ *
+ * @return boolean
+ * @access public
+ */
+ public function set($name, $value, $expiration = 0)
+ {
+ // 0 - don't use compression.
+ return $this->_handler->set($name, $value, $expiration);
+ }
+
+ /**
+ * Stores value in cache (only if it's not there already)
+ *
+ * @param string $name Name.
+ * @param mixed $value Value.
+ * @param integer $expiration Expiration.
+ *
+ * @return boolean
+ * @access public
+ */
+ public function add($name, $value, $expiration = 0)
+ {
+ // 0 - don't use compression.
+ return $this->_handler->add($name, $value, $expiration);
+ }
+
+ /**
+ * Deletes key from cache
+ *
+ * @param string $name Name.
+ *
+ * @return boolean
+ * @access public
+ */
+ public function delete($name)
+ {
+ return $this->_handler->delete($name, 0);
+ }
+
+ }
class ApcCacheHandler extends kCacheHandler {
@@ -974,4 +1090,4 @@
{
return xcache_unset($name);
}
- }
\ No newline at end of file
+ }
Index: memcache_test.php
===================================================================
--- memcache_test.php
+++ memcache_test.php
@@ -19,7 +19,55 @@
$application =& kApplication::Instance();
$application->Init();
-$application->Run();
-$application->Done();
-$end = microtime(true);
\ No newline at end of file
+echo 'PHP ' . PHP_VERSION . '
';
+
+switch ( $application->GetVar('step') ) {
+ case 'delete':
+ echo 'Deleting Infinite Key
' . PHP_EOL;
+ $application->deleteCache('infinite_key');
+
+ echo 'Deleting Expiring Key
' . PHP_EOL;
+ $application->deleteCache('expiring_key');
+
+ echo 'Deleting Infinite Added Key
' . PHP_EOL;
+ $application->deleteCache('infinite_added_key');
+
+ echo 'Deleting Expiring Added Key
' . PHP_EOL;
+ $application->deleteCache('expiring_added_key');
+ break;
+
+ case 'set':
+ $result = $application->setCache('infinite_key', 'infinite value');
+ echo 'Setting Infinite Key: ';
+ var_dump($result);
+
+ $result = $application->setCache('expiring_key', 'expiring value', 30);
+ echo 'Setting Expiring Key: ';
+ var_dump($result);
+
+ $result = $application->addCache('infinite_added_key', 'infinite added value');
+ echo 'Adding Infinite Adding Key: ';
+ var_dump($result);
+
+ $result = $application->addCache('expiring_added_key', 'expiring added value', 30);
+ echo 'Adding Expiring Adding Key: ';
+ var_dump($result);
+ break;
+
+ default:
+ echo 'Getting Infinite Key:' . PHP_EOL;
+ var_dump($application->getCache('infinite_key'));
+
+ echo 'Getting Expiring Key:' . PHP_EOL;
+ var_dump($application->getCache('expiring_key'));
+
+ echo 'Getting Infinite Added Key:' . PHP_EOL;
+ var_dump($application->getCache('infinite_added_key'));
+
+ echo 'Getting Expiring Added Key:' . PHP_EOL;
+ var_dump($application->getCache('expiring_added_key'));
+ break;
+}
+
+$end = microtime(true);