Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Updated options to include all Memcached options
Browse files Browse the repository at this point in the history
- Tests are segfaulting currently with multiple test (hasItems())
  • Loading branch information
weierophinney committed Dec 20, 2011
1 parent 64a3daa commit 6690b98
Show file tree
Hide file tree
Showing 4 changed files with 811 additions and 16 deletions.
85 changes: 73 additions & 12 deletions library/Zend/Cache/Storage/Adapter/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
namespace Zend\Cache\Storage\Adapter;

use ArrayObject,
Memcached as MemcachedResource,
stdClass,
Traversable,
Zend\Cache\Exception,
Zend\Cache\Storage\Capabilities;

Expand All @@ -39,17 +41,10 @@ class Memcached extends AbstractAdapter
/**
* Memcached instance
*
* @var Memcached
* @var MemcachedResource
*/
protected $memcached;

/**
* The used namespace separator
*
* @var string
*/
protected $namespaceSeparator = ':';

/**
* Constructor
*
Expand All @@ -63,7 +58,7 @@ public function __construct()
throw new Exception\ExtensionNotLoadedException("Memcached extension is not loaded");
}

$this->memcached= new Memcached();
$this->memcached= new MemcachedResource();

}

Expand All @@ -72,8 +67,8 @@ public function __construct()
/**
* Set options.
*
* @param stringTraversable|WinCacheOptions $options
* @return WinCache
* @param string|Traversable|MemcachedOptions $options
* @return Memcached
* @see getOptions()
*/
public function setOptions($options)
Expand All @@ -83,13 +78,29 @@ public function setOptions($options)
&& !$options instanceof MemcachedOptions
) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects an array, a Traversable object; '
'%s expects an array, a Traversable object, or a MemcachedOptions object; '
. 'received "%s"',
__METHOD__,
(is_object($options) ? get_class($options) : gettype($options))
));
}

if (!$options instanceof MemcachedOptions) {
$options = new MemcachedOptions($options);
}

$this->options = $options;

// Set memcached options, using options map to map to Memcached constants
$map = $options->getOptionsMap();
foreach ($options->toArray() as $key => $value) {
if (!array_key_exists($key, $map)) {
// skip keys for which there are not equivalent options
continue;
}
$this->memcached->setOption($map[$key], $value);
}

return $this;
}

Expand Down Expand Up @@ -661,6 +672,55 @@ public function decrementItem($key, $value, array $options = array())

/* non-blocking */

/**
* Find items.
*
* Options:
* - ttl <float> optional
* - The time-to-life (Default: ttl of object)
* - namespace <string> optional
* - The namespace to use (Default: namespace of object)
* - tags <array> optional
* - Tags to search for used with matching modes of
* Zend\Cache\Storage\Adapter::MATCH_TAGS_*
*
* @param int $mode Matching mode (Value of Zend\Cache\Storage\Adapter::MATCH_*)
* @param array $options
* @return boolean
* @throws Exception
* @see fetch()
* @see fetchAll()
*
* @triggers find.pre(PreEvent)
* @triggers find.post(PostEvent)
* @triggers find.exception(ExceptionEvent)
*/
public function find($mode = self::MATCH_ACTIVE, array $options=array())
{
throw Exception\RuntimeException(sprintf(
'%s is not yet implemented',
__METHOD__
));
}

/**
* Fetches the next item from result set
*
* @return array|boolean The next item or false
* @throws Exception
* @see fetchAll()
*
* @triggers fetch.pre(PreEvent)
* @triggers fetch.post(PostEvent)
* @triggers fetch.exception(ExceptionEvent)
*/
public function fetch()
{
throw Exception\RuntimeException(sprintf(
'%s is not yet implemented',
__METHOD__
));
}

/* cleaning */

Expand Down Expand Up @@ -751,6 +811,7 @@ public function getCapabilities()
),
'maxTtl' => 0,
'staticTtl' => false,
'tagging' => false,
'ttlPrecision' => 1,
'useRequestTime' => false,
'expiredRead' => false,
Expand Down
Loading

0 comments on commit 6690b98

Please sign in to comment.