Skip to content

Commit

Permalink
Merge pull request zendframework#1 from prolic/cache
Browse files Browse the repository at this point in the history
small fix in MissingDependencyException, PhpDoc for Zend\Cache\Pattern
  • Loading branch information
marc-mabe committed Dec 7, 2011
2 parents 1c58817 + 220dc70 commit 9a268fd
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

namespace Zend\Cache\Exception;

class MissingDependencyException extends RuntimeException implements \Zend\Cache\Exception
class MissingDependencyException extends RuntimeException
{}
4 changes: 2 additions & 2 deletions library/Zend/Cache/Pattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public function __construct($options = array());
* Set pattern options
*
* @param array|Traversable $options
* @return Zend\Cache\Pattern
* @return Pattern
*/
public function setOptions($options);

/**
* Get all pattern options
*
* return array
* @return array
*/
public function getOptions();

Expand Down
17 changes: 17 additions & 0 deletions library/Zend/Cache/Pattern/AbstractPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,23 @@
abstract class AbstractPattern implements Cache\Pattern
{

/**
* Constructor
*
* @param array|Traversable $options
*/
public function __construct($options = array())
{
$this->setOptions($options);
}

/**
* Set pattern options
*
* @param array|Traversable $options
* @return AbstractPattern
* @throws InvalidArgumentException
*/
public function setOptions($options)
{
if (!($options instanceof Traversable) && !is_array($options)) {
Expand All @@ -29,6 +41,11 @@ public function setOptions($options)
return $this;
}

/**
* Get all pattern options
*
* @return array
*/
public function getOptions()
{
return array();
Expand Down
22 changes: 22 additions & 0 deletions library/Zend/Cache/Pattern/CallbackCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class CallbackCache extends AbstractPattern
*/
protected $_cacheOutput = true;

/**
* Constructor
*
* @param array|Traversable $options
* @throws InvalidArgumentException
*/
public function __construct($options = array())
{
parent::__construct($options);
Expand All @@ -31,6 +37,11 @@ public function __construct($options = array())
}
}

/**
* Get all pattern options
*
* @return array
*/
public function getOptions()
{
$options = parent::getOptions();
Expand Down Expand Up @@ -180,6 +191,17 @@ public function generateKey($callback, array $args = array(), array $options = a
return $this->_generateKey($callback, $args, $options);
}

/**
* Generate a unique key in base of a key representing the callback part
* and a key representing the arguments part merged using md5($callbackKey.$argumentsKey).
*
* @param callback $callback A valid callback
* @param array $args Callback arguments
* @param array $options Options
* @return string
* @throws \Zend\Cache\Exception\InvalidArgumentException
* @throws \Zend\Cache\Exception\RuntimeException
*/
protected function _generateKey($callback, array $args, array $options)
{
$callbackKey = '';
Expand Down
93 changes: 90 additions & 3 deletions library/Zend/Cache/Pattern/CaptureCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,21 @@ class CaptureCache extends AbstractPattern
*/
protected $_tags = array();

/**
* Constructor
*
* @param array|Traversable $options
*/
public function __construct($options = array())
{
parent::__construct($options);
}

/**
* Get all pattern options
*
* @return array
*/
public function getOptions()
{
return array(
Expand All @@ -69,34 +79,67 @@ public function getOptions()
);
}

/**
* Set public directory
*
* @param null|string $dir
* @return CaptureCache
*/
public function setPublicDir($dir)
{
$this->_publicDir = $dir;
return $this;
}

/**
* Get public directory
*
* @return null|string
*/
public function getPublicDir()
{
return $this->_publicDir;
}

/**
* Set index filename
*
* @param string $filename
* @return CaptureCache
*/
public function setIndexFilename($filename)
{
$this->_indexFilename = (string)$filename;
return $this;
}

/**
* Get index filename
*
* @return string
*/
public function getIndexFilename()
{
return $this->_indexFilename;
}

/**
* Set file locking
*
* @param bool $flag
* @return CaptureCache
*/
public function setFileLocking($flag)
{
$this->_fileLocking = (boolean)$flag;
return $this;
}

/**
* Get file locking
*
* @return bool
*/
public function getFileLocking()
{
return $this->_fileLocking;
Expand All @@ -106,7 +149,7 @@ public function getFileLocking()
* Set a storage for tagging
*
* @param \Zend\Cache\Storage\Adapter $storage
* @return \Zend\Cache\Pattern\CaptureCache
* @return CaptureCache
*/
public function setTagStorage(Adapter $storage)
{
Expand All @@ -128,7 +171,7 @@ public function getTagStorage()
* Set cache item key to store tags
*
* @param $tagKey string
* @return Zend\Cache\Pattern\CaptureCache
* @return CaptureCache
*/
public function setTagKey($tagKey)
{
Expand All @@ -154,7 +197,7 @@ public function getTagKey()
* Set tags to store
*
* @param array $tags
* @return Zend\Cache\Pattern\CaptureCache
* @return CaptureCache
*/
public function setTags(array $tags)
{
Expand Down Expand Up @@ -205,6 +248,14 @@ public function start($pageId = null, array $options = array())
return false;
}

/**
* Get from cache
*
* @param null|string $pageId
* @param array $options
* @return bool|string
* @throws RuntimeException
*/
public function get($pageId = null, array $options = array())
{
if (($pageId = (string)$pageId) === '') {
Expand All @@ -226,6 +277,13 @@ public function get($pageId = null, array $options = array())
return false;
}

/**
* Checks if a cache with given id exists
*
* @param null|string $pageId
* @param array $options
* @return bool
*/
public function exists($pageId = null, array $options = array())
{
if (($pageId = (string)$pageId) === '') {
Expand All @@ -239,6 +297,14 @@ public function exists($pageId = null, array $options = array())
return file_exists($file);
}

/**
* Remove from cache
*
* @param null|string $pageId
* @param array $options
* @throws RuntimeException
* @return void
*/
public function remove($pageId = null, array $options = array())
{
if (($pageId = (string)$pageId) === '') {
Expand All @@ -257,6 +323,9 @@ public function remove($pageId = null, array $options = array())
}
}

/**
* Clear cache
*/
public function clear(/*TODO*/)
{
// TODO
Expand All @@ -272,6 +341,12 @@ protected function _detectPageId()
return $_SERVER['REQUEST_URI'];
}

/**
* Get filename for page id
*
* @param string $pageId
* @return string
*/
protected function _pageId2Filename($pageId)
{
$filename = basename($pageId);
Expand All @@ -283,6 +358,12 @@ protected function _pageId2Filename($pageId)
return $filename;
}

/**
* Get path for page id
*
* @param string $pageId
* @return string
*/
protected function _pageId2Path($pageId)
{
$path = rtrim(dirname($pageId), '/');
Expand Down Expand Up @@ -310,6 +391,12 @@ protected function _flush($output)
return false;
}

/**
* Save the cache
*
* @param $output
* @throws RuntimeException
*/
protected function _save($output)
{
$path = $this->_pageId2Path($this->_pageId);
Expand Down
34 changes: 34 additions & 0 deletions library/Zend/Cache/Pattern/ClassCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,40 @@ class ClassCache extends CallbackCache
*/
protected $_storage;

/**
* The entity
*
* @var null|string
*/
protected $_entity = null;

/**
* Cache by default
*
* @var bool
*/
protected $_cacheByDefault = true;

/**
* Cache methods
*
* @var array
*/
protected $_cacheMethods = array();

/**
* Non-cache methods
*
* @var array
*/
protected $_nonCacheMethods = array();

/**
* Constructor
*
* @param array|Traversable $options
* @throws InvalidArgumentException
*/
public function __construct($options = array())
{
parent::__construct($options);
Expand All @@ -31,6 +60,11 @@ public function __construct($options = array())
}
}

/**
* Get all pattern options
*
* @return array
*/
public function getOptions()
{
$options = parent::getOptions();
Expand Down
Loading

0 comments on commit 9a268fd

Please sign in to comment.