Skip to content

Commit

Permalink
Doctrine classes renaming and movement (new location), coverage test …
Browse files Browse the repository at this point in the history
…at 89%, 1570 of 1570 successful
  • Loading branch information
fruit committed Aug 16, 2010
1 parent 8659625 commit 6682087
Show file tree
Hide file tree
Showing 18 changed files with 171 additions and 110 deletions.
11 changes: 5 additions & 6 deletions README.markdown
Expand Up @@ -89,9 +89,6 @@ are not (atomic counter).
# if "tags" is NULL (~), it will
# be the same as cache (e.i. sfMemcacheTaggingCache)

metadata:
class: CacheMetadata # this class responses to save/fetch data and tags
# from/to cache with custom serialization/de-serialization
logger:
class: sfFileCacheTagLogger # to disable logger, set class to "sfNoCacheTagLogger"
param:
Expand Down Expand Up @@ -250,19 +247,21 @@ are not (atomic counter).
# 0: without micro time, version length 10 digits
# 5: with micro time part, version length 15 digits
# (allowed decimal numbers in range [0, 6]
metadata_class: CacheMetadata # this class responses to save/fetch data and tags
# from/to cache with custom serialization/de-serialization

#object_class_tag_name_provider: # you can customize tag name naming
# # useful for multi-environment models
# - ProjectToolkit # [class name]
# - formatObjectClassName # [static method name]

Minified ``app.yml`` content:
Minified recommended ``app.yml`` content:

all:
sfcachetaggingplugin:
template_lock: "%SF_ENVIRONMENT%_lock_%s"
template_tag: "%SF_ENVIRONMENT%_tag_%s"
microtime_precision: 5
template_tag: "%SF_ENVIRONMENT%_tag_%s"

## Usage ##

Expand Down
10 changes: 2 additions & 8 deletions config/sfCacheTaggingPluginConfiguration.class.php
Expand Up @@ -8,11 +8,6 @@
* file that was distributed with this source code.
*/

if (! defined('E_USER_DEPRECATED'))
{
define('E_USER_DEPRECATED', E_USER_WARNING);
}

/**
* sfCacheTaggingPlugin configuration
*
Expand Down Expand Up @@ -44,12 +39,11 @@ public function initialize ()
);

$manager->setAttribute(
Doctrine_Core::ATTR_RESULT_CACHE, new sfDoctrineProxyCache()
Doctrine_Core::ATTR_RESULT_CACHE, new Doctrine_Cache_Proxy()
);

$manager->setAttribute(
Doctrine_Core::ATTR_QUERY_CLASS,
'Cachetaggable_Doctrine_Query'
Doctrine_Core::ATTR_QUERY_CLASS, 'Doctrine_Query_Cachetaggable'
);

$manager->setAttribute(Doctrine::ATTR_USE_DQL_CALLBACKS, true);
Expand Down
Expand Up @@ -17,13 +17,11 @@ class sfAPCTaggingCache extends sfAPCCache
{
public function getCacheKeys ()
{
// apc_cache_info returns false, if APC is disabled
// no reasons to check it - all methods available after
// calling self::__construct
$infos = apc_cache_info('user');

if (! is_array($infos['cache_list']))
{
return;
}

$keys = array();

foreach ($infos['cache_list'] as $info)
Expand Down
33 changes: 15 additions & 18 deletions lib/cache/sfTaggingCache.class.php
Expand Up @@ -274,7 +274,7 @@ public function remove ($key)
{
$cacheMetadata = $this->getDataCache()->get($key);

$cacheMetadataClassName = $this->getMetadataClassName();
$cacheMetadataClassName = sfCacheTaggingToolkit::getMetadataClassName();

if ($cacheMetadata instanceof $cacheMetadataClassName)
{
Expand Down Expand Up @@ -343,7 +343,7 @@ public function addTagsToCache ($key, array $tags, $append = true)
{
$cacheMetadata = $this->getDataCache()->get($key);

$cacheMetadataClassName = $this->getMetadataClassName();
$cacheMetadataClassName = sfCacheTaggingToolkit::getMetadataClassName();

if ($cacheMetadata instanceof $cacheMetadataClassName)
{
Expand Down Expand Up @@ -375,7 +375,7 @@ public function addTagsToCache ($key, array $tags, $append = true)
*/
public function set ($key, $data, $timeout = null, array $tags = array())
{
$cacheMetadataClassName = $this->getMetadataClassName();
$cacheMetadataClassName = sfCacheTaggingToolkit::getMetadataClassName();

$cacheMetadata = new $cacheMetadataClassName($data, $tags);

Expand Down Expand Up @@ -482,7 +482,7 @@ public function getTags ($key)
{
$value = $this->getDataCache()->get($key);

$cacheMetadataClassName = $this->getMetadataClassName();
$cacheMetadataClassName = sfCacheTaggingToolkit::getMetadataClassName();

if ($value instanceof $cacheMetadataClassName)
{
Expand Down Expand Up @@ -536,7 +536,7 @@ public function get ($key, $default = null)
{
$cacheMetadata = $this->getDataCache()->get($key, $default);

$cacheMetadataClassName = $this->getMetadataClassName();
$cacheMetadataClassName = sfCacheTaggingToolkit::getMetadataClassName();

# check data exist in cache and data content is a tags container
if ($cacheMetadata instanceof $cacheMetadataClassName)
Expand Down Expand Up @@ -672,7 +672,11 @@ public function clean ($mode = sfCache::ALL)
protected function generateLockKey ($key)
{
return sprintf(
sfConfig::get('app_sfcachetaggingplugin_template_lock', 'lock_%s'), $key
sfConfig::get(
'app_sfcachetaggingplugin_template_lock',
sprintf('%s_lock', sfConfig::get('sf_environment') . '_%s')
),
$key
);
}

Expand All @@ -685,7 +689,11 @@ protected function generateLockKey ($key)
protected function generateTagKey ($key)
{
return sprintf(
sfConfig::get('app_sfcachetaggingplugin_template_tag', 'tag_%s'), $key
sfConfig::get(
'app_sfcachetaggingplugin_template_tag',
sprintf('%s_tag', sfConfig::get('sf_environment') . '_%s')
),
$key
);
}

Expand All @@ -699,17 +707,6 @@ public function getContentTagHandler ()
return $this->contentTagHandler;
}

/**
* Return option "metadata.class".
* If not set, returns default class name "CacheMetadata".
*
* @return string
*/
protected function getMetadataClassName ()
{
return $this->getOption('metadata.class', 'CacheMetadata');
}

/**
* @return array registered keys in storage
*/
Expand Down
34 changes: 29 additions & 5 deletions lib/util/sfCacheTaggingToolkit.class.php
Expand Up @@ -88,6 +88,14 @@ public static function getPrecision ()
return $presision;
}

/**
* @return string
*/
public static function getMetadataClassName ()
{
return sfConfig::get('app_sfcachetaggingplugin_metadata_class', 'CacheMetadata');
}

/**
* Format passed tags to the array
*
Expand Down Expand Up @@ -174,12 +182,22 @@ public static function listenOnComponentMethodNotFoundEvent (sfEvent $event)
{
$taggingCache = sfCacheTaggingToolkit::getTaggingCache();
}
catch (sfException $e)
catch (sfCacheDisabledException $e)
{
sfCacheTaggingToolkit::notifyApplicationLog($e->getMessage(), sfLogger::NOTICE);
sfCacheTaggingToolkit::notifyApplicationLog(
__CLASS__, $e->getMessage(), sfLogger::NOTICE
);

return;
}
catch (sfConfigurationException $e)
{
sfCacheTaggingToolkit::notifyApplicationLog(
__CLASS__, $e->getMessage(), sfLogger::WARNING
);

return;
}

try
{
Expand All @@ -188,7 +206,8 @@ public static function listenOnComponentMethodNotFoundEvent (sfEvent $event)
);

$event
->setReturnValue(call_user_func_array($callable, $event['arguments']));
->setReturnValue(call_user_func_array($callable, $event['arguments']))
;
}
catch (BadMethodCallException $e)
{
Expand Down Expand Up @@ -228,11 +247,16 @@ public static function getBaseClassName ($className)
return $className;
}

public static function notifyApplicationLog ($message, $priority = null)
/**
* @param mixed $object object or string, or null
* @param string $message
* @param int $priority sfLogger::* see constants
*/
public static function notifyApplicationLog ($object, $message, $priority = null)
{
ProjectConfiguration::getActive()
->getEventDispatcher()
->notify(new sfEvent($this, 'application.log', array($message, $priority)))
->notify(new sfEvent($object, 'application.log', array($message, $priority)))
;
}
}
Expand Up @@ -17,7 +17,7 @@
* @subpackage doctrine
* @author Ilya Sabelnikov <fruit.dev@gmail.com>
*/
class sfDoctrineProxyCache extends Doctrine_Cache_Driver
class Doctrine_Cache_Proxy extends Doctrine_Cache_Driver
{
/**
* Short method to retrieve sfTaggingCache for internal use
Expand All @@ -42,7 +42,9 @@ protected function _doSave ($id, $data, $ttl = false)
}
catch (sfCacheDisabledException $e)
{
# be silent - sf_cache is disabled for this environment
sfCacheTaggingToolkit::notifyApplicationLog(
__CLASS__, $e->getMessage(), sfLogger::NOTICE
);
}

return false;
Expand All @@ -62,7 +64,9 @@ protected function _doSaveWithTags ($id, $data, $ttl, $tags)
}
catch (sfCacheDisabledException $e)
{
# be silent - sf_cache is disabled for this environment
sfCacheTaggingToolkit::notifyApplicationLog(
__CLASS__, $e->getMessage(), sfLogger::NOTICE
);
}

return false;
Expand All @@ -79,7 +83,9 @@ protected function _getCacheKeys ()
}
catch (sfCacheDisabledException $e)
{
sfCacheTaggingToolkit::notifyApplicationLog($e->getMessage(), sfLogger::NOTICE);
sfCacheTaggingToolkit::notifyApplicationLog(
__CLASS__, $e->getMessage(), sfLogger::NOTICE
);
}

return;
Expand All @@ -97,7 +103,9 @@ protected function _doDelete ($id)
}
catch (sfCacheDisabledException $e)
{
# be silent - sf_cache is disabled for this environment
sfCacheTaggingToolkit::notifyApplicationLog(
__CLASS__, $e->getMessage(), sfLogger::NOTICE
);
}

return false;
Expand All @@ -115,7 +123,9 @@ protected function _doContains ($id)
}
catch (sfCacheDisabledException $e)
{
# be silent - sf_cache is disabled for this environment
sfCacheTaggingToolkit::notifyApplicationLog(
__CLASS__, $e->getMessage(), sfLogger::NOTICE
);
}

return false;
Expand All @@ -135,7 +145,9 @@ protected function _doFetch ($id, $testCacheValidity = true)
}
catch (sfCacheDisabledException $e)
{
# be silent - sf_cache is disabled for this environment
sfCacheTaggingToolkit::notifyApplicationLog(
__CLASS__, $e->getMessage(), sfLogger::NOTICE
);
}

return false;
Expand Down
Expand Up @@ -94,7 +94,7 @@ public function getTags ($deep = false)
}
catch (sfCacheDisabledException $e)
{
sfCacheTaggingToolkit::notifyApplicationLog($e->getMessage(), sfLogger::NOTICE);
$this->notifyApplicationLog($e);

return array();
}
Expand Down Expand Up @@ -181,7 +181,7 @@ public function addTags ($tags)
}
catch (sfCacheDisabledException $e)
{
sfCacheTaggingToolkit::notifyApplicationLog($e->getMessage(), sfLogger::NOTICE);
$this->notifyApplicationLog($e);
}
}

Expand All @@ -202,7 +202,7 @@ public function addTag ($tagName, $tagVersion)
}
catch (sfCacheDisabledException $e)
{
sfCacheTaggingToolkit::notifyApplicationLog($e->getMessage(), sfLogger::NOTICE);
$this->notifyApplicationLog($e);
}
}

Expand All @@ -221,7 +221,7 @@ public function removeTags ()
}
catch (sfCacheDisabledException $e)
{
sfCacheTaggingToolkit::notifyApplicationLog($e->getMessage(), sfLogger::NOTICE);
$this->notifyApplicationLog($e);
}
}

Expand All @@ -239,10 +239,17 @@ public function delete (Doctrine_Connection $conn = null, $clearColl = true)
}
catch (sfCacheDisabledException $e)
{
sfCacheTaggingToolkit::notifyApplicationLog($e->getMessage(), sfLogger::NOTICE);
$this->notifyApplicationLog($e);
}

return $returnValue;
}

protected function notifyApplicationLog (Exception $e)
{
sfCacheTaggingToolkit::notifyApplicationLog(
$this, $e->getMessage(), sfLogger::NOTICE
);
}
}

Expand Up @@ -20,7 +20,7 @@
* @param array $params
* @return Doctrine_Collection the root collection
*/
class Cachetaggable_Doctrine_Query extends Doctrine_Query
class Doctrine_Query_Cachetaggable extends Doctrine_Query
{
/**
* @see Doctrine_Query::execute()
Expand Down Expand Up @@ -71,7 +71,7 @@ public function execute ($params = array(), $hydrationMode = null)
$cached = $this->getCachedForm($result);

if (
$cacheDriver instanceof sfDoctrineProxyCache
$cacheDriver instanceof Doctrine_Cache_Proxy
&&
$result instanceof Doctrine_Collection_Cachetaggable)
{
Expand Down
Expand Up @@ -84,7 +84,7 @@ public function postDelete (Doctrine_Event $event)
}
catch (sfCacheException $e)
{

}

$this->preDeleteTagName = null;
Expand Down

1 comment on commit 6682087

@fruit
Copy link
Owner Author

@fruit fruit commented on 6682087 Aug 16, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, prepared package.xml, changed channel (from pear.symfony-project.com to plugins.symfony-project.com)

Please sign in to comment.