Skip to content

Commit

Permalink
All deprecated methods removed at all, new API version 2.0, added som…
Browse files Browse the repository at this point in the history
…e new tests, test coverage is 87%, # of tests is 1252
  • Loading branch information
fruit committed Jun 20, 2010
1 parent 55ed945 commit 4cfdc61
Show file tree
Hide file tree
Showing 16 changed files with 305 additions and 295 deletions.
3 changes: 2 additions & 1 deletion lib/cache/sfContentTagHandler.class.php
Expand Up @@ -19,7 +19,8 @@ class sfContentTagHandler
/**
* holder's namespaces
* Namespace name should be "UpperCamelCased"
* This names is used in method patterns "call%sMethod", where %s is User/Page/Action
* This names is used in method patterns "call%sMethod",
* where %s is User/Page/Action
*/
const
NAMESPACE_USER = 'User',
Expand Down
41 changes: 9 additions & 32 deletions lib/cache/sfTagCache.class.php
Expand Up @@ -118,21 +118,6 @@ public function getDataCache ()
return $this->dataCache;
}

/**
* Returns cache class for data caching
*
* @deprecated since v1.3.1 use sfTagCache::getDataCache()
* @return sfCache
*/
public function getCache ()
{
sfCacheTaggingToolkit::triggerMethodIsDeprecated(
__METHOD__, 'sfTagCache::getDataCache', 'v1.3.1'
);

return $this->getDataCache();
}

/**
* Returns cache class for locks
*
Expand All @@ -143,20 +128,6 @@ public function getLockerCache ()
return $this->lockerCache;
}

/**
* @deprecated since v1.3.1 use sfTagCache::getLockerCache()
*
* @return sfCache
*/
public function getLocker ()
{
sfCacheTaggingToolkit::triggerMethodIsDeprecated(
__METHOD__, 'sfTagCache::getLockerCache', 'v1.3.1'
);

return $this->getLockerCache();
}

/**
* @since v1.4.0
* parent::has() replaced by $this->get()
Expand Down Expand Up @@ -276,7 +247,9 @@ public function set ($key, $data, $lifetime = null, $tags = null)
{
foreach ($extendedData->tags as $tagKey => $value)
{
$this->setTag($tagKey, $value, sfCacheTaggingToolkit::getTagLifetime());
$this->setTag(
$tagKey, $value, sfCacheTaggingToolkit::getTagLifetime()
);
}
}
}
Expand Down Expand Up @@ -323,7 +296,9 @@ public function getTag ($tagKey)
{
$result = $this->getDataCache()->get($this->generateTagKey($tagKey));

$this->writeChar($result ? 'G' :'g', $this->generateTagKey($tagKey), $result);
$this->writeChar(
$result ? 'G' :'g', $this->generateTagKey($tagKey), $result
);

return $result;
}
Expand Down Expand Up @@ -532,7 +507,9 @@ public function lock ($key, $expire = 2)
$memcache = $this->getLockerCache()->getBackend();

$result = $memcache->add(
sprintf('%s%s', $this->getLockerCache()->getOption('prefix'), $lockKey),
sprintf(
'%s%s', $this->getLockerCache()->getOption('prefix'), $lockKey
),
1,
$expire
);
Expand Down
108 changes: 16 additions & 92 deletions lib/cache/sfViewCacheTagManager.class.php
Expand Up @@ -9,7 +9,9 @@
*/

/**
* This is extended cache manager with additional methods to work with cache tags.
* This is extended cache manager with additional methods to work
* with cache tags.
*
* The most important difference from sfViewCacheManager is support to use
* sepparate cache systems for data and locks (performance reasons).
*
Expand Down Expand Up @@ -98,7 +100,10 @@ protected function setEventDispatcher (sfEventDispatcher $eventDispatcher)
*
* @see sfViewCacheManager::initialize
*/
public function initialize ($context, sfCache $taggingCache, $options = array())
public function initialize ($context,
sfCache $taggingCache,
$options = array()
)
{
if (! $taggingCache instanceof sfTagCache)
{
Expand Down Expand Up @@ -151,20 +156,6 @@ public function getTaggingCache ()
return $this->taggingCache;
}

/**
* @deprecated use sfViewCacheTagManager::getTaggingCache() since v1.4.4
*
* @return sfTagCache
*/
public function getTagger ()
{
sfCacheTaggingToolkit::triggerMethodIsDeprecated(
__METHOD__, 'sfViewCacheTagManager::getTaggingCache', 'v1.4.4'
);

return $this->getTaggingCache();
}

/**
* @param sfTagCache $taggingCache
* @return sfViewCacheTagManager
Expand Down Expand Up @@ -207,83 +198,13 @@ public function stopWithTags ($key, $lifetime = null)
{
$data = ob_get_clean();

$this->getTaggingCache()->set(
$key,
$data,
$lifetime,
$this->getContentTagHandler()->getContentTags(sfContentTagHandler::NAMESPACE_USER)
);

return $data;
}

/**
* Temporary stores tag keys, while buffer is writing
*
* @param array $tags
* @deprecated since v1.4.4
* @return sfViewCacheTagManager
*/
public function setTags ($tags)
{
sfCacheTaggingToolkit::triggerMethodIsDeprecated(__METHOD__, null, 'v1.4.4');

$this
->getContentTagHandler()
->setContentTags($tags, sfContentTagHandler::NAMESPACE_USER)
;

return $this;
}

/**
* Appends the tags
*
* @param array|Doctrine_Record|Doctrine_Collection_Cachetaggable|ArrayAccess $tags
* @deprecated since v1.4.4
* @return sfViewCacheTagManager
*/
public function addTags ($tags)
{
sfCacheTaggingToolkit::triggerMethodIsDeprecated(__METHOD__, null, 'v1.4.4');

$this->setTags(
array_merge($this->getTags(), sfCacheTaggingToolkit::formatTags($tags))
);

return $this;
}

/**
* Returns added tags
*
* @deprecated since v1.4.4
* @return array
*/
public function getTags ()
{
sfCacheTaggingToolkit::triggerMethodIsDeprecated(__METHOD__, null, 'v1.4.4');

return $this
$tags = $this
->getContentTagHandler()
->getContentTags(sfContentTagHandler::NAMESPACE_USER);
}

/**
* Clears the tags
*
* @deprecated since v1.4.4
* @return sfViewCacheTagManager
*/
public function clearTags ()
{
sfCacheTaggingToolkit::triggerMethodIsDeprecated(__METHOD__, null, 'v1.4.4');

$this
->getContentTagHandler()
->removeContentTags(sfContentTagHandler::NAMESPACE_USER);

$this->getTaggingCache()->set($key, $data, $lifetime, $tags);

return $this;
return $data;
}

/**
Expand Down Expand Up @@ -393,7 +314,8 @@ public function has ($internalUri)
*
* @param string $uri The internal URI
*
* @return array An array composed of the cached content and the view attribute holder
* @return array An array composed of the cached content and
* the view attribute holder
*/
public function getActionCache ($uri)
{
Expand Down Expand Up @@ -505,7 +427,9 @@ public function setPageCache ($uri)
);

// save content in cache
$saved = $this->set(serialize($this->context->getResponse()), $uri, $pageTags);
$saved = $this->set(
serialize($this->context->getResponse()), $uri, $pageTags
);

if ($saved and sfConfig::get('sf_web_debug'))
{
Expand Down
8 changes: 6 additions & 2 deletions lib/cache/sfViewCacheTagManagerBridge.class.php
Expand Up @@ -51,7 +51,9 @@ protected function getManager ()
* If user calls:
* $this->setActionTags($tags);
* transform it to:
* $this->setContentTags($tags, sfContentTagHandler::NAMESPACE_ACTION);
* $this->setContentTags(
* $tags, sfContentTagHandler::NAMESPACE_ACTION
* );
*
* If user calls:
* $this->hasPageTag();
Expand Down Expand Up @@ -79,9 +81,11 @@ public function __call ($method, $arguments)

array_push($arguments, $contentNamespace);

$nsLength = strlen($contentNamespace);

# transforms "getPageTag" to "getContentTag"
$contentAbstractMethod = substr_replace(
$method, 'Content', strpos($method, $contentNamespace), strlen($contentNamespace)
$method, 'Content', strpos($method, $contentNamespace), $nsLength
);

try
Expand Down
37 changes: 24 additions & 13 deletions lib/doctrine/collection/Cachetaggable.class.php
Expand Up @@ -9,8 +9,9 @@
*/

/**
* Adds functionality to fetch collection tags, also it stores other associated collection tags
* in the Doctrine_Collection_Cachetaggable instance
* Adds functionality to fetch collection tags, also it stores other
* associated collection tags in the Doctrine_Collection_Cachetaggable
* instance
*
* @package sfCacheTaggingPlugin
* @author Ilya Sabelnikov <fruit.dev@gmail.com>
Expand Down Expand Up @@ -74,14 +75,17 @@ protected function fetchTags (self $collection = null)
{
$tags[$object->getTagName()] = $object->getObjectVersion();

$latestFoundVersion = $latestFoundVersion < $object->getObjectVersion()
? $object->getObjectVersion()
: $latestFoundVersion;
$latestFoundVersion =
$latestFoundVersion < $object->getObjectVersion()
? $object->getObjectVersion()
: $latestFoundVersion;
}

if (null !== ($first = $collection->getFirst()))
{
$tagger = sfContext::getInstance()->getViewCacheManager()->getTaggingCache();
$tagger = sfContext::getInstance()
->getViewCacheManager()
->getTaggingCache();

$lastSavedVersion = $tagger->getTag(get_class($first));

Expand All @@ -93,11 +97,12 @@ protected function fetchTags (self $collection = null)
else
{
/**
* little hack, if collection is empty, emulate collection, without any tags
* but version should be staticaly fixed (in day range)
* little hack, if collection is empty, emulate collection,
* without any tags, but version should be staticaly
* fixed (in day range)
*
* repeating calls with relative microtime always refresh collection tag
* so, here is fixed value
* so, here is day-fixed value
*/
$tags[$collection->getTable()->getClassnameToReturn()]
= sfCacheTaggingToolkit::generateVersion(strtotime('today'));
Expand All @@ -106,8 +111,6 @@ protected function fetchTags (self $collection = null)
return $tags;
}



/**
* Returns this collection and added tags
*
Expand All @@ -117,7 +120,9 @@ public function getTags ()
{
$this->addTags($this->fetchTags());

return $this->getContentTagHandler()->getContentTags($this->getNamespace());
return $this
->getContentTagHandler()
->getContentTags($this->getNamespace());
}

/**
Expand All @@ -131,7 +136,9 @@ public function getTags ()
*/
public function addTags ($tags)
{
$this->getContentTagHandler()->addContentTags($tags, $this->getNamespace());
$this
->getContentTagHandler()
->addContentTags($tags, $this->getNamespace());
}

/**
Expand All @@ -157,6 +164,10 @@ public function removeTags ()
$this->getContentTagHandler()->removeContentTags($this->getNamespace());
}

/**
* @see Doctrine_Collection::delete()
* @return Doctrine_Collection_Cachetaggable
*/
public function delete (Doctrine_Connection $conn = null, $clearColl = true)
{
$returnValue = parent::delete($conn, $clearColl);
Expand Down

0 comments on commit 4cfdc61

Please sign in to comment.