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

Commit

Permalink
Merge branch 'cache_fixes' of https://github.com/marc-mabe/zf2 into h…
Browse files Browse the repository at this point in the history
…otfix/cache-options-improvements
  • Loading branch information
weierophinney committed Feb 9, 2012
5 parents 1f29b3e + a75171a + 9a8e72f + 814716e + bc4058b commit 926e71f
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 167 deletions.
14 changes: 0 additions & 14 deletions src/Pattern/AbstractPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,6 @@ abstract class AbstractPattern implements Pattern
*/
public function setOptions(PatternOptions $options)
{
if (!is_array($options)
&& !$options instanceof Traversable
&& !$options instanceof PatternOptions
) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects an array, a Traversable object, or an PatternOptions instance; '
. 'received "%s"',
__METHOD__,
(is_object($options) ? get_class($options) : gettype($options))
));
}

if (!$options instanceof PatternOptions) {
$options = new PatternOptions($options);
}
Expand All @@ -68,8 +56,6 @@ public function setOptions(PatternOptions $options)
return $this;
}



/**
* Get all pattern options
*
Expand Down
8 changes: 5 additions & 3 deletions src/Pattern/CallbackCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ class CallbackCache extends AbstractPattern
{
/**
* Set options
*
* @param PatternOptions $options
*
* @param PatternOptions $options
* @return CallbackCache
* @throws Exception\InvalidArgumentException if missing storage option
*/
public function setOptions(PatternOptions $options)
{
parent::setOptions($options);

if (!$options->getStorage()) {
throw new Exception\InvalidArgumentException("Missing option 'storage'");
}
Expand Down Expand Up @@ -72,7 +73,8 @@ public function call($callback, array $args = array(), array $options = array())
return $rs[0];
}

if ( ($cacheOutput = $classOptions->getCacheOutput()) ) {
$cacheOutput = $classOptions->getCacheOutput();
if ($cacheOutput) {
ob_start();
ob_implicit_flush(false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Pattern/CaptureCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function start($pageId = null, array $options = array())
}

ob_start(array($this, 'flush'));
ob_implicitflush(false);
ob_implicit_flush(false);
$this->pageId = $pageId;

return false;
Expand Down
72 changes: 36 additions & 36 deletions src/Pattern/PatternOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function setCacheByDefault($cacheByDefault)
$this->cacheByDefault = $cacheByDefault;
return $this;
}

/**
* Do we cache by default?
*
Expand Down Expand Up @@ -220,7 +220,7 @@ public function setCacheOutput($cacheOutput)
$this->cacheOutput = (bool) $cacheOutput;
return $this;
}

/**
* Will we cache output?
*
Expand Down Expand Up @@ -253,7 +253,7 @@ public function setClass($class)
$this->class = $class;
return $this;
}

/**
* Get class name
*
Expand Down Expand Up @@ -281,7 +281,7 @@ public function setClassCacheMethods(array $classCacheMethods)
$this->classCacheMethods = $this->recursiveStrtolower($classCacheMethods);
return $this;
}

/**
* Get list of methods from which to cache return values
*
Expand Down Expand Up @@ -309,7 +309,7 @@ public function setClassNonCacheMethods(array $classNonCacheMethods)
$this->classNonCacheMethods = $this->recursiveStrtolower($classNonCacheMethods);
return $this;
}

/**
* Get list of methods from which NOT to cache return values
*
Expand All @@ -327,8 +327,8 @@ public function getClassNonCacheMethods()
* Set directory permissions
*
* Sets {@link $dirUmask} property to inverse of provided value.
*
* @param string $dirPerm
*
* @param string $dirPerm
* @return PatternOptions
*/
public function setDirPerm($dirPerm)
Expand All @@ -347,7 +347,7 @@ public function setDirPerm($dirPerm)
* Gets directory permissions
*
* Proxies to {@link $dirUmask} property, returning its inverse.
*
*
* @return int
*/
public function getDirPerm()
Expand Down Expand Up @@ -377,7 +377,7 @@ public function setDirUmask($dirUmask)
$this->dirUmask = $dirUmask;
return $this;
}

/**
* Get directory umask
*
Expand Down Expand Up @@ -405,7 +405,7 @@ public function setFileLocking($fileLocking)
$this->fileLocking = (bool) $fileLocking;
return $this;
}

/**
* Is file locking enabled?
*
Expand All @@ -423,8 +423,8 @@ public function getFileLocking()
* Set file permissions
*
* Sets {@link $fileUmask} property to inverse of provided value.
*
* @param string $filePerm
*
* @param string $filePerm
* @return PatternOptions
*/
public function setFilePerm($filePerm)
Expand All @@ -443,7 +443,7 @@ public function setFilePerm($filePerm)
* Gets file permissions
*
* Proxies to {@link $fileUmask} property, returning its inverse.
*
*
* @return int
*/
public function getFilePerm()
Expand Down Expand Up @@ -478,7 +478,7 @@ public function setFileUmask($fileUmask)
$this->fileUmask = $fileUmask;
return $this;
}

/**
* Get file umask
*
Expand All @@ -503,7 +503,7 @@ public function setIndexFilename($indexFilename)
$this->indexFilename = (string) $indexFilename;
return $this;
}

/**
* Get value for index filename
*
Expand All @@ -530,7 +530,7 @@ public function setObject($object)
$this->object = $object;
return $this;
}

/**
* Get object to cache
*
Expand All @@ -555,7 +555,7 @@ public function setObjectCacheMagicProperties($objectCacheMagicProperties)
$this->objectCacheMagicProperties = (bool) $objectCacheMagicProperties;
return $this;
}

/**
* Should we cache magic properties?
*
Expand All @@ -581,7 +581,7 @@ public function setObjectCacheMethods(array $objectCacheMethods)
$this->objectCacheMethods = $this->normalizeObjectMethods($objectCacheMethods);
return $this;
}

/**
* Get list of object methods for which to cache return values
*
Expand Down Expand Up @@ -612,7 +612,7 @@ public function setObjectKey($objectKey)
}
return $this;
}

/**
* Get object key
*
Expand All @@ -638,7 +638,7 @@ public function setObjectNonCacheMethods(array $objectNonCacheMethods)
$this->objectNonCacheMethods = $this->normalizeObjectMethods($objectNonCacheMethods);
return $this;
}

/**
* Get list of object methods for which NOT to cache return values
*
Expand All @@ -663,7 +663,7 @@ public function setPublicDir($publicDir)
$this->publicDir = (string) $publicDir;
return $this;
}

/**
* Get location of public directory
*
Expand Down Expand Up @@ -695,7 +695,7 @@ public function setStorage($storage)
$this->storage = $storage;
return $this;
}

/**
* Get storage adapter
*
Expand Down Expand Up @@ -727,7 +727,7 @@ public function setTagKey($tagKey)
$this->tagKey = $tagKey;
return $this;
}

/**
* Get tag key
*
Expand All @@ -752,7 +752,7 @@ public function setTags(array $tags)
$this->tags = $tags;
return $this;
}

/**
* Get tags
*
Expand Down Expand Up @@ -781,7 +781,7 @@ public function setTagStorage($tagStorage)
$this->tagStorage = $tagStorage;
return $this;
}

/**
* Get storage adapter for tags
*
Expand All @@ -798,8 +798,8 @@ public function getTagStorage()
/**
* Recursively apply strtolower on all values of an array, and return as a
* list of unique values
*
* @param array $array
*
* @param array $array
* @return array
*/
protected function recursiveStrtolower(array $array)
Expand All @@ -811,11 +811,11 @@ protected function recursiveStrtolower(array $array)

/**
* Normalize object methods
*
* Recursively casts values to lowercase, then determines if any are in a
*
* Recursively casts values to lowercase, then determines if any are in a
* list of methods not handled, raising an exception if so.
*
* @param array $methods
* @param array $methods
* @return array
* @throws Exception\InvalidArgumentException
*/
Expand All @@ -836,13 +836,13 @@ protected function normalizeObjectMethods(array $methods)
*
* Allows specifying a umask as either an octal or integer. If the umask
* fails required permissions, raises an exception.
*
* @param int|string $mask
* @param callable Callback used to verify the umask is acceptable for the given purpose
*
* @param int|string $umask
* @param callable $comparison Callback used to verify the umask is acceptable for the given purpose
* @return int
* @throws Exception\InvalidArgumentException
*/
protected function normalizeUmask($mask, $comparison)
protected function normalizeUmask($umask, $comparison)
{
if (is_string($umask)) {
$umask = octdec($umask);
Expand All @@ -857,8 +857,8 @@ protected function normalizeUmask($mask, $comparison)

/**
* Create a storage object from a given specification
*
* @param array|string|StorageAdapter $storage
*
* @param array|string|StorageAdapter $storage
* @return StorageAdapter
*/
protected function storageFactory($storage)
Expand Down
16 changes: 2 additions & 14 deletions src/Storage/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,6 @@ public function __destruct()
*/
public function setOptions($options)
{
if (!is_array($options)
&& !$options instanceof Traversable
&& !$options instanceof AdapterOptions
) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects an array, a Traversable object, or an AdapterOptions instance; '
. 'received "%s"',
__METHOD__,
(is_object($options) ? get_class($options) : gettype($options))
));
}

if (!$options instanceof AdapterOptions) {
$options = new AdapterOptions($options);
}
Expand Down Expand Up @@ -696,7 +684,7 @@ public function incrementItems(array $keyValuePairs, array $options = array())

$ret = true;
foreach ($keyValuePairs as $key => $value) {
$ret = $this->incrementItems($key, $value, $options) && $ret;
$ret = $this->incrementItem($key, $value, $options) && $ret;
}
return $ret;
}
Expand Down Expand Up @@ -738,7 +726,7 @@ public function decrementItems(array $keyValuePairs, array $options = array())

$ret = true;
foreach ($keyValuePairs as $key => $value) {
$ret = $this->decrementMulti($key, $value, $options) && $ret;
$ret = $this->decrementItem($key, $value, $options) && $ret;
}
return $ret;
}
Expand Down
10 changes: 8 additions & 2 deletions src/Storage/Adapter/AbstractZendServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,14 @@ public function getMetadata($key, array $options = array())
}

$internalKey = $options['namespace'] . self::NAMESPACE_SEPARATOR . $key;
$result = ($this->zdcFetch($internalKey) !== false) ? array() : false;
if ($this->zdcFetch($internalKey) === false) {
if (!$options['ignore_missing_items']) {
throw new Exception\ItemNotFoundException("Key '{$internalKey}' not found");
}
$result = false;
} else {
$result = array();
}

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
Expand Down Expand Up @@ -427,7 +434,6 @@ public function removeItem($key, array $options = array())
$this->normalizeOptions($options);
$args = new ArrayObject(array(
'key' => & $key,
'value' => & $value,
'options' => & $options,
));

Expand Down
Loading

0 comments on commit 926e71f

Please sign in to comment.